I have a scene, which is a field with some trees. When I get to the edge of the map, the movement scoots sideways instead of forward. The texture seems to go on forever. Is there a way to put a “fence” at the edge of the world to indicate where it is? Here is the code that draws the ground. As I said, I’m really new to OpenGl and I don’t know what the glLockArraysEXT really does. Any helpful hints would be appreciated. Thanks!
// select the ground texture
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glLockArraysEXT(0, MAP_X * MAP_Z * 6);
// loop through all the triangle strips
for (int z = 0; z < MAP_Z-1; z++)
// draw the triangles in this strip
glDrawElements(GL_TRIANGLE_STRIP, MAP_X * 2, GL_UNSIGNED_INT, &g_indexArray[z * MAP_X * 2]);
// if the compiled arrays extension is available, unlock the arrays
} // end DrawGround()
Hmmm not sure if I understood you correctly but could it be that you dont clear the colorbuffer?
I second the motion for a clarification of the question. Are you talking about a visual fence, or a physical ( object collision ) one?
I am talking about a visual fence. I cleared the color and depth buffer and still the ground seems to go on forever. I can walk in the -z direction for a time and then run into an invisible wall (my world boundaries?) The same happens with the -x, x and z directions. I can see objects I randomly created outside this area, but cannot walk up to them. On a vertex array, how do I found out what the coordinates are for the outer boundary?
The map’s specified size is X=16, Z=8, scale = 25.0f
(BTW: I’m modifying example code in the Prima Tech’s Game Development series on OpenGL Game Programming)
I’m still having trouble visualizing your problem. But i’ll go out on a limb with a guess.
Do a sanity test:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
This should wipe the screen to black.
As for the bounds of your world, how are you setting up the geometry if you don’t know the bounds of your array?
The suggestion did turn the screen black.(except the trees and butterflies I’ve added.)
The geometry was already there. I’m trying to figure out how to place something where I want it specifically, not randomly. The trees and butterflies are random. I know that the X length is 16 and the z lenght is 8. Allowing for 3 float numbers for each vertex, I figured there would be 16,384 vertices in the vertex array. Pretty overwhelming if I wanted to figure out each one and put it into a display list.
When I tried to put a girl in a specific place, she didn’t turn up where I expected her to be.
Does the vector array start at (0.0f, 0.0f, 0.0f) and go to (16.0f, 0.0f, 8.0f)? And then each vertex is offset by 3 indices (i.e. point 1 would be element numbers 0, 1 & 2, point 2 would be element number 3, 4 & 5, etc??)
Ok, as a side, display lists are great for some thing, not so hot for others. Don’t use them for things that are going to change frequently, just the stuff that will remain mostly static in your world. Recompiling display lists is not something you want to do in excess, when it would do just as well to go ahead and render the model then and there. Give me a clue as to the kind of geometry you have, terrain, human models, …
Thanks again for your quick reply. The game I’m trying to modify is in Chapter 15 in the OpenGL Game Programming book (cacti) This is the website as I can’t post code on this board.
Prima-Tech's web page
I’v modified the cacti to be trees. Added butterflies, using the same coding, but a different bitmap. I’ve added a picture of a girl, but it’s not correct because it doesn’t show up in the right place. Eventually, I’ll replace the girl with a model, but I haven’t figured that out yet either. I’ll end up putting is some collision detection using bounding spheres on the butterflies and catch them with a net. Kind of a stupid game, but hey what the heck, I’m just a girl (as my teacher says) what can you expect. I’m not sure if you can learn all this in one semester, but I’m giving it a try!
In a nutshell, right now I’m trying to set up the scene, then I’ll add the model and the collision detection. (You can do that with the objects, i.e. butterflies, with the vertex arrays, can’t you??) Would this be better to just use the display lists? It would just be the ground and the fence, which should only have to be rendered once, right? (As much time as I have spent on this, I could probably have figured out every one of the 16K + vertices!)
Although I’ll probably never be a game programmer, I find this sorta fun and certainly challenging!
, signing off for the night, gotta work in the a.m.
Never Mind. I put the scene in a display list and it works fine. Thanks for all your help.