I've written a simple program which draws an OpenGL quad on the screen at 0,0,0. It fills the entire screen ( which makes sense to me ) and if I move it 1 unit left or right, up or down, it moves accordingly ( I can see black background to the right or left, bottom or top respectively. ) But if I move it beyond 1.0 on the z axis, it doesn't seem to be drawn.
So I'm wondering if this is because the camera range is very low by default and I haven't increased it. I found a page that said it defaulted to 0 for near and 1 for far ( which is exactly the limit ) and thought that would fix it. So I added the glDepthRange(0,1000) call to fix that, but that made no difference.
So I don't know if it's a perspective thing or what. Bear in mind, I have no OpenGL books and I'm trying to figure this stuff out from a bunch of websites and the modules, so it's a bit tricky. I'm only really playing with OpenGL to force myself to pick up all the new BMax features ( OOP, pointers, etc ) but I can't really go on until I can draw something beyond z=1.
I'd prefer not to post all the code as I've written it all as a library and there's a lot of stuff which is not really necessary. So I've snipped what I think are the only important bits.
OpenGL Initialization code :
Quad Render bit:
MeshList is a TList of meshes. Each Mesh has a QuadList. A Quad has four vertices, which are numbered 1-4 in the order they should be draw. As you can see, it totals the global position of the mesh and the local position of the vertex within that mesh and draws it. This works fine with z ranges between 0 and 1, and affecting the x and y positions works too, so I'm pretty sure there's no problem with any of this.
I'm guessing it's something else I should be doing when I initialize OpenGL, but I have no idea what else there is.
So I'm wondering if this is because the camera range is very low by default and I haven't increased it. I found a page that said it defaulted to 0 for near and 1 for far ( which is exactly the limit ) and thought that would fix it. So I added the glDepthRange(0,1000) call to fix that, but that made no difference.
So I don't know if it's a perspective thing or what. Bear in mind, I have no OpenGL books and I'm trying to figure this stuff out from a bunch of websites and the modules, so it's a bit tricky. I'm only really playing with OpenGL to force myself to pick up all the new BMax features ( OOP, pointers, etc ) but I can't really go on until I can draw something beyond z=1.
I'd prefer not to post all the code as I've written it all as a library and there's a lot of stuff which is not really necessary. So I've snipped what I think are the only important bits.
OpenGL Initialization code :
bglCreateContext(SW,SH,SD,HZ,Flags) glShadeModel(GL_SMOOTH) glClearColor(0.0,0.0,0.0,0.0) glDepthRange(0,1000) glClearDepth(1.0) ' Depth Buffer Setup glEnable(GL_DEPTH_TEST) ' Enables Depth Testing glDepthFunc(GL_LEQUAL) ' The Type Of Depth Test To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) ' USE THE BEST PERSPECTIVE CALCULATIONS
Quad Render bit:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ' RENDER QUADS glBegin(GL_QUADS) For M=EachIn MeshList If M.Quads=True For Q=EachIn M.QuadList glColor3f(1.0,1.0,1.0) glVertex3f(M.X+Q.V1.X,M.Y+Q.V1.Y,M.Z+Q.V1.Z) glVertex3f(M.X+Q.V2.X,M.Y+Q.V2.Y,M.Z+Q.V2.Z) glVertex3f(M.X+Q.V3.X,M.Y+Q.V3.Y,M.Z+Q.V3.Z) glVertex3f(M.X+Q.V4.X,M.Y+Q.V4.Y,M.Z+Q.V4.Z) Next End If Next glEnd()
MeshList is a TList of meshes. Each Mesh has a QuadList. A Quad has four vertices, which are numbered 1-4 in the order they should be draw. As you can see, it totals the global position of the mesh and the local position of the vertex within that mesh and draws it. This works fine with z ranges between 0 and 1, and affecting the x and y positions works too, so I'm pretty sure there's no problem with any of this.
I'm guessing it's something else I should be doing when I initialize OpenGL, but I have no idea what else there is.
