2 questions

Blitz3D Forums/Blitz3D Programming/2 questions

abacadabad(Posted 2003) [#1]
Hello everyone!
I have two questions which I would greatly appreciate help with;

1. I am trying to create a camera and take a "picture" from bove the tearrin, save it, and texture it on a cube. It all seems to go ok but the texture is pictured as 2d int he top corner and the cube is black. I think its the buffering, whihc I dont understand. Can anyone shed some light?

2. I have a mesh, and a function to cycle through all the verticies and colour them according to their height. How would I be able to paint for example, all triangles above a certain height one texture and all below as another?

Thanks heaps for your help!! :-)


_PJ_(Posted 2003) [#2]
The first one should be possible. I have seen code (maybe in the Code Archives) to achieve such an effect (to texture from the screen buffer onto a mesh). Perhaps an alternative would be to use SaveBuffer() and save the screen to a bitmap file to be Loaded back in as a texture as normal.
If you could post some code for what you have, it maybe possible to change that too!

The second one is possible, because this is what many Terrain creation programs have done. I do not know how, though...


jhocking(Posted 2003) [#3]
I'm not exactly sure what you are describing in your first question. I mean, I understand what you are trying to do but I don't understand your description of what is happening. It sounds like instead of the picture appearing on the cube the picture is being drawn straight to the screen. In that case you are clearly A) not applying the image to the cube (eg. by copying the image to the texture buffer) and B) drawing the image to the screen using 2D commands like DrawImage.

As for the second question you can easily get vertex heights using commands like TerrainY (if you are using a Blitz terrain entity) or VertexY.


Ross C(Posted 2003) [#4]
here, i coded this quickly so it's far from perfect, but may give you a starting point.
it grabs the screen image and creates a texture and then textures the cube with it.
press the 1 key to perform texturing. to run this code you need an square image (ie 128x128) called height.bmp

Graphics3D 800,600

SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,20,0
RotateEntity camera,90,0,0

texture=LoadTexture("height.bmp")

map=LoadTerrain("height.bmp")
TerrainShading map,True
PositionEntity map,-5,0,-5
ScaleEntity map,0.5,5,0.5
EntityTexture map,texture

light=CreateLight()


cube=CreateCube()
TurnEntity cube,30,30,30
PositionEntity cube,0,2,-9



While Not KeyHit(1)


If KeyHit(2) Then Gosub takepicture

TurnEntity cube,1,1,1



UpdateWorld
RenderWorld
Flip
Wend
End


.takepicture
cubetex=CreateTexture(800,600); create a texture the size of the screen
ctex=CreateImage(800,600); create an image the size of the screen
GrabImage ctex,0,0; grab the image onscreen and put it in the image ctex
CameraClsMode camera,False,True; set camera mode so 2d graphics appear as backround
Cls; clear the screen
SetBuffer TextureBuffer(cubetex); set the drawing buffer to the texture
DrawImage ctex,0,0; draw the image grabbed from the screen
SetBuffer BackBuffer(); set the buffer back to the back buffer
CameraClsMode camera,True,True; reset the cameraclsmode
EntityTexture cube,cubetex; texture the cube with the screen
Return



abacadabad(Posted 2003) [#5]
Thnkyou so much! I will go and try all of these and let you know what happens.
Thanks again! :-)