Troubleshooting: Vertex arrays and camera postioning

I am working on the base of a 3d object renderer. My objects are created in Blender, and exported via some custom python scripts into a file format that I can load.

So far, I set up my glEnables, and all starting states, load the objects into a vertex array, and activate it, index array, position the camera, and then call glDrawElements

But I can see only the clear color I have set.

I have carefully tried disabling culling, keeping the shading model flat, and choosing a color that will contrast.

I have tried it in ortho2d projects, 3d projects, I have tried gluLookAt, etc, etc, etc, and still I see nothing.

My object for testing is a cube, centered at the origin, with 2 units a side.

Can anyone offer any hints for debugging a beast like this? It’s really hard to develop an engine when you can’t get the most basic code working!

–Thanks,
–Colin

You can always try to find some vertex array code that you KNOW work, and put it in your code. If this works, it’s probably your own vertex array thats bugging. Otherwise, it’s something else (surprise )…

Did you enable each vertex pointer with glEnableClientState() or whatever the functions is called, because you don’t enable them with glEnable()

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_DOUBLE, 0, m->vert);
glDrawElements(GL_QUADS, (m->numindex)*4, GL_INT, m->index);

Have I missed anything?

I have also added debugging to print out the arrays and verify the data is correctly loaded.

Here is my frame set up code:
glEnable(GL_DEPTH_TEST); //z-buffer
glDepthFunc(GL_LESS);
glShadeModel(GL_FLAT);
glDisable(GL_CULL_FACE);

//set up the backdrop
glClearColor(0.1,0.1,0.1,1.0);
glColor3f(1.0,1.0,1.0);
//Set up projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Specifically, as I mentioned that my test object was a 8 vertex, 6 faced cube drawn with GL_QUAD’s centered on the origin and spanning
(-1,-1,-1) to (1,1,1)
The background is supposed to be dark grey, and I was hoping to see a white cube.
with glOrtho2d set to the above values, this should show up as a white square.

All I see is the background!

Thanks for your suggestions, and I will try and find some working vertex array code to try it with.

I am also going to try manually rendering the array.

Any other suggestions? Modes I should try?

You appear to have an error in your posted code. glVertexPointer takes 5 arguments, but you show only 4. Could you correct that please? It is important that we see all arguments of glVertexPointer.

Also, what is m->numindex in glDrawElements in this instance (when drawing your cube)?

[This message has been edited by DFrey (edited 10-17-2000).]

Here is the structure for m:
struct model_ {
double * vert;
int * index;
int numindex;
int numvert;
}

numindex is actually a face count of the mesh. Hence numindex*4 is the number of elements in the index array. I really should rename it, it’s confusing.

I just finished trying it with manually, calling glVertex3f(…) and manually deferencing the elements of the arrays.
It worked.

Hence, I am sure it is a problem with my vertex arrays.

That localised, here are my hypotoses:
a) in the red book, it always shows using 2d arrays for the vertices. I assumed it was a nicety that made sense for printing, as all those values were hard coded. But that would map to a flat piece of memory anyways. Since I am dynamically building my object in ram, I have to use a flat ptr to an array, right?

b) as for glVertexPointer:
void glVertexPointer( GLint size,
GLenum type,
GLsizei stride,
const GLvoid *pointer )

nope, just 4 parameters.

Hmm Any other hints?

Thanks.

Concerning the glVertexPointer, someone is wrong. Here is what my documentation says:
void glVertexPointer(
GLint size,
GLenum type,
GLsizei stride,
GLsizei count,
const GLvoid *pointer
);

And that is what I’ve been using.

Originally posted by DFrey:
[b]Concerning the glVertexPointer, someone is wrong. Here is what my documentation says:
void glVertexPointer(
GLint size,
GLenum type,
GLsizei stride,
GLsizei count,
const GLvoid *pointer
);

And that is what I’ve been using.[/b]

Wow! That is interesting…
I will double check that.
I see two possible cases: a) both are correct (overloaded?) or b) one is from using the extension, the other is gl 1.1 standard…

The one I am using is documented at http://trant.sgi.com/opengl/docs/man_pages/hardcopy/GL/html/gl/ which I link I followed to from OpenGL.org|developers|documentation.

Why do I find this interesting? Both of ours link and run. As far as I can tell, I am using the opengl 1.1 standard one. Do you have to use the glGetExtension stuff?

Thanks for the info.

Ah, yes, I’m using the 1.0 extension. Oh well, I’m stumped on your problem then.

Originally posted by DFrey:
Ah, yes, I’m using the 1.0 extension. Oh well, I’m stumped on your problem then.

Good news!
I zapped my problem!

glDrawElements(GL_QUADS, (m->numindex)*4, GL_INT, m->index);

A little more debugging using glGetError() solved it.
The error was GL_INVALID_ENUM following that line above.

Armed with the knowledge of where the problem was, I was able to re-read the man page on it, and lo and behold:
GL_INT was not a valid option. GL_UNSIGNED_INT was, so 2 quick code changes (on the structure, and on the file reader) and voila!

Thanks for your help.