Jump to content

change the texture!


Gilmer
 Share

Recommended Posts

I have a model, which will begin to load with this material:

 

texture0="cardif.dds"
texture1="cardot.dds"
texture6="reflect.dds"

cullface=0

shader="abstract::mesh_cube_reflection_bump_difuse_specular.vert","abstract::mesh_cube_reflection_bump_difuse_specular.frag"
shadowshader="abstract::mesh_shadow.vert",""

 

 

But I want the script in this model, in the update it, pass the image of the a texture, which was taken from the buffer(GetColorBuffer()) to the "texture6=...", because this textures will always changing, like a reflect, so i would like to change in the shader too, and show this change. The my question is, what are the commands necessary for this? I tried a lot of commands to set materials, shaders, textures....but so far i not getting results..

 

Edit: i need use, some like the BindTexture()??

Link to comment
Share on other sites

Hi Gilmer.

The code should look something like this:

 

Entity myEntity("abstract::myEntity.gmf");
Mesh myMesh=myMesh.FindChild("myMesh");
Material myMat=myEntity.GetSurface(1).GetMaterial();

Texture tex;
tex=buffer.GetColor();
myMat.SetTexture(tex);

 

This is how I did it. Hope it will help.

Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64

3ds max / photoshop CS3 / C++

http://www.arbuznikov.com

Link to comment
Share on other sites

Hello Arbuz, thanks for feedback, i did something, and really worked. But not yet completed, i noticed the followin: when i create a texture to skybox and cubemap, by the photoshop using the NVidia dds, i need set to "cubemap" instead of "2D Texture". But if a create in the leadwerks, get the buffers to use as texture, it does not work, because it dont is set for "cubemap". Have someway to i create this texture in memory, being that i want use to cubemap, and not to comum texture?! Im using a shader to fit the texture in the model, as cubemap. This is the code witch im using in the script:

 

require("scripts/framewerk")
require("scripts/class")
require("Scripts/constants/engine_const")
require("Scripts/LinkedList")
require("Scripts/filesystem")
require("Scripts/math/math")

local class=CreateClass(...)

fw=GetGlobalObject("framewerk")

--CONST
drawscreen=0 --desenhar na tela?

function class:CreateObject(model)
local object=self.super:CreateObject(model)

chave=0


cameracube = CreateCamera()
CameraClearMode(cameracube,1+2)
cameracube:SetPosition(model:GetPosition())
cameracube:Hide()
rotcam = cameracube:GetRotation()

maincamera = fw.main.camera

-- buffers
mainbuffer = CurrentBuffer()
buffercam = CreateBuffer(GraphicsWidth(),GraphicsHeight(),1+2+4)
buffertex = CreateBuffer(256*6,256,1+2+4)
bufferprint = CreateBuffer(256*6,256,BUFFER_COLOR)

colorbuffer2=CreateTexture(256*6,256,2+4)
TextureFilter(colorbuffer2,1)


entity=FindChild(model,"cube")
surf=GetSurface(entity,1)
mat=GetSurfaceMaterial(surf)
shader=GetMaterialShader(mat)

texreflect=LoadTexture("abstract::reflect.dds")
texreflect2=LoadTexture("abstract::reflect2.dds")
texxadrez=LoadTexture("abstract::reflect_xadrez.dds")
texxadrez2=LoadTexture("abstract::reflect_xadrez.dds")



function object:Update()


	model:Hide()
	maincamera:Hide()
	cameracube:Show()


	--Visao1
	SetBuffer(buffercam)
	cameracube:SetRotation(rotcam)

	world=fw.main.world
	bgworld=fw.background.world

	RenderWorld()

	SetWorld(bgworld)
	RenderWorld()

	colorbuffer = GetColorBuffer(buffercam)
	SetBuffer(buffertex)
	DrawImage(colorbuffer,0,256,256,-256)

	SetWorld(world)

	--Visao2
	SetBuffer(buffercam)
	cameracube:Turnf(0,90,0)

	RenderWorld()

	SetWorld(bgworld)
	RenderWorld()

	colorbuffer = GetColorBuffer(buffercam)
	SetBuffer(buffertex)

	DrawImage(colorbuffer,256,256,256,-256)

	SetWorld(world)

	--Visao3
	SetBuffer(buffercam)
	cameracube:Turnf(0,90,0)

	RenderWorld()

	SetWorld(bgworld)
	RenderWorld()

	colorbuffer = GetColorBuffer(buffercam)
	SetBuffer(buffertex)

	DrawImage(colorbuffer,512,256,256,-256)

	SetWorld(world)

	--Visao4
	SetBuffer(buffercam)
	cameracube:Turnf(0,90,0)

	RenderWorld()

	SetWorld(bgworld)
	RenderWorld()

	colorbuffer = GetColorBuffer(buffercam)
	SetBuffer(buffertex)

	DrawImage(colorbuffer,768,256,256,-256)

	SetWorld(world)

	--Visao5
	SetBuffer(buffercam)
	cameracube:Turnf(0,90,0)
	cameracube:Turnf(90,0,0)

	RenderWorld()

	SetWorld(bgworld)
	RenderWorld()

	colorbuffer = GetColorBuffer(buffercam)
	SetBuffer(buffertex)

	DrawImage(colorbuffer,1024,256,256,-256)
	cameracube:Turnf(-90,0,0)

	SetWorld(world)

	--Visao6
	SetBuffer(buffercam)
	cameracube:Turnf(-90,0,0)

	RenderWorld()

	SetWorld(bgworld)
	RenderWorld()

	colorbuffer = GetColorBuffer(buffercam)
	SetBuffer(buffertex)

	DrawImage(colorbuffer,1280,256,256,-256)
	cameracube:Turnf(90,0,0)




	--CRIA A IMAGEM
	SetWorld(world)

	SetBuffer(mainbuffer)

	cameracube:Hide()
	maincamera:Show()

	colorbuffer2 = GetColorBuffer(buffertex)

	SetMaterialTexture(mat,colorbuffer2,6)


	if drawscreen==1 then
		DrawImage(colorbuffer2,0,256,256*6,-256)
		DrawImage(texreflect,0,512,256*6,-256)
	end
	Flip()


	model:Show()




	--## SALVA A IMAGEM DO BUFFER PARA TESTES
	if chave==20 then
		SetBuffer(bufferprint)
		DrawImage(GetColorBuffer(buffertex),0,0,256*6,256)
		SetBuffer(BackBuffer())

		SaveBuffer(bufferprint,"testebuffer.tga")
		chave=30
	end

	if chave<21 then
		chave=chave+1
	end

end

end


 

and this is the shader:

http://www.leadwerks.com/forum/viewtopic.php?p=43333#p43333

Link to comment
Share on other sites

Thanks Masterxilo, but where should I put it in code? And for example, as each side of the texture is 256x256, so the texture would have a whole 256*6x256, right? The texture is that i create have to have this size or should i put it as 256x256, so that it will add a side by side?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...