Sign in to follow this  
Ahl

Help with my scene drawing code, please?

Recommended Posts

I don't know if I'm doing this right. I've ironed out all of the compiler errors. There are no run time errors. I'm not entirely sure everything is being loaded into the VBOs properly but I wanted to make sure all my basic render code is good first.

[code]
bool AhlywoGraphix::DrawGLScene() // Here's Where We Do All The Drawing
{
RenderList.sort();

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Matrix
glColor3f(1.0, 1.0, 1.0);

glBindBufferARB( GL_ARRAY_BUFFER_ARB, VBO_ID ); // <== WTF to do with that?

glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glEnableClientState( GL_NORMAL_ARRAY ); // Enable Normal Arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays

for (RenderIt = RenderList.begin(); RenderIt != RenderList.end(); ++RenderIt)
{
glTranslatef((*RenderIt)->x, (*RenderIt)->y, (*RenderIt)->z);

glRotatef((*RenderIt)->xrot, 1.0f, 0.0f, 0.0f);
glRotatef((*RenderIt)->yrot, 0.0f, 1.0f, 0.0f);
glRotatef((*RenderIt)->zrot, 0.0f, 0.0f, 1.0f);

glVertexPointer( 3, GL_FLOAT, 0, (GLvoid *)(*RenderIt)->Model->VBOVertexOffset ); // Set The Vertex Pointer To The Vertex Buffer
glTexCoordPointer( 2, GL_FLOAT, 0, (GLvoid *)(*RenderIt)->Model->VBOTexCoordOffset ); // Set The TexCoord Pointer To The TexCoord Buffer
glNormalPointer(GL_FLOAT, 0, (GLvoid *)(*RenderIt)->Model->VBONormalOffset ); // Set the Normal Pointer to the texcoord Buffer

glDrawArrays( GL_TRIANGLES, 0, (*RenderIt)->Model->VertexCount ); // Draw All Of The Triangles At Once
}
glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
glDisableClientState( GL_NORMAL_ARRAY ); // Disable Normal Arrays
glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays
return true; // Keep Going
}
[/code]

Share this post


Link to post
Share on other sites
[quote name='Ahl' timestamp='1305788920' post='4812902']
I don't know if I'm doing this right. I've ironed out all of the compiler errors. There are no run time errors. I'm not entirely sure everything is being loaded into the VBOs properly but I wanted to make sure all my basic render code is good first.

[code]
bool AhlywoGraphix::DrawGLScene() // Here's Where We Do All The Drawing
{
RenderList.sort();

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Matrix
glColor3f(1.0, 1.0, 1.0);

glBindBufferARB( GL_ARRAY_BUFFER_ARB, VBO_ID ); // <== WTF to do with that?

glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
glEnableClientState( GL_NORMAL_ARRAY ); // Enable Normal Arrays
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays

for (RenderIt = RenderList.begin(); RenderIt != RenderList.end(); ++RenderIt)
{
glTranslatef((*RenderIt)->x, (*RenderIt)->y, (*RenderIt)->z);

glRotatef((*RenderIt)->xrot, 1.0f, 0.0f, 0.0f);
glRotatef((*RenderIt)->yrot, 0.0f, 1.0f, 0.0f);
glRotatef((*RenderIt)->zrot, 0.0f, 0.0f, 1.0f);

glVertexPointer( 3, GL_FLOAT, 0, (GLvoid *)(*RenderIt)->Model->VBOVertexOffset ); // Set The Vertex Pointer To The Vertex Buffer
glTexCoordPointer( 2, GL_FLOAT, 0, (GLvoid *)(*RenderIt)->Model->VBOTexCoordOffset ); // Set The TexCoord Pointer To The TexCoord Buffer
glNormalPointer(GL_FLOAT, 0, (GLvoid *)(*RenderIt)->Model->VBONormalOffset ); // Set the Normal Pointer to the texcoord Buffer

glDrawArrays( GL_TRIANGLES, 0, (*RenderIt)->Model->VertexCount ); // Draw All Of The Triangles At Once
}
glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
glDisableClientState( GL_NORMAL_ARRAY ); // Disable Normal Arrays
glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays
return true; // Keep Going
}
[/code]
[/quote]

I read that you should set the vertex pointer as last (just before glDrawArrays). For the sake of readability I would dereference the iterator once at the start of the loop and then use it in the rest of the loop body.
After that you could also move the drawing code to the renderable (the elements in the RenderList).

Share this post


Link to post
Share on other sites
1. The routine expects that the MODELVIEW matrix stack is active. (Its not a fault, I just wanted to mention it for clarity.)

2. Regarding your "WTF" line: The VBO_ID addresses the VBO you want the vertex attribute arrays to belong to. The VBO_ID [i]must[/i] formerly be successfully generated by invoking glGenBuffers(...) or glGenBuffersARB(...), resp.

3. The glTranslatef(...) and glRotatef(...) invocations for all the RenderIt objects are concatenated. I.e. the position of the 2nd object depends on the position and orientation of the 1st object. You probably want to use some glPushMarix() / glPopMatrix() wrapping each set of transformations.

4. The used combination of glRotatef(...)'s is legal but uncommon.

5. Invoke glVertexPointer(...) after the other gl???Pointer routines.

6. Using the matrix stack is deprecated since OpenGL version 3.1 (IIRC).

ATM I don't see other issues.

Share this post


Link to post
Share on other sites



you have

glVertexPointer( 3, GL_FLOAT, 0, (GLvoid *)(*RenderIt)->Model->VBOVertexOffset ); // Set The Vertex Pointer To The Vertex Buffer
glTexCoordPointer( 2, GL_FLOAT, 0, (GLvoid *)(*RenderIt)->Model->VBOTexCoordOffset ); // Set The TexCoord Pointer To The TexCoord Buffer
glNormalPointer(GL_FLOAT, 0, (GLvoid *)(*RenderIt)->Model->VBONormalOffset ); //








omg i do it like: so for vertex pointer i have an dynamic array of structure called t3dpoint where i have floats x,y,z

and the last param of func is the first index of array




glVertexPointer(3, GL_FLOAT, sizeof(t3dpoint), &VBO_V[0]);
glNormalPointer(GL_FLOAT, sizeof(t3dpoint),&VBO_N[0]);
glTexCoordPointer(2, GL_FLOAT, sizeof(textpoint),&VBO_T[0]);




this should fix the problem and one thing remove bindbufferarb :P




Share this post


Link to post
Share on other sites
Alright I got it to work. It was a mixture of the issues you all pointed out as well as something being wrong with my VBO loading code. I can load one model in and it works fine but if I try to load another one neither model works. I'll get to that in a second.

What is the general policy on using glLoadIdentity() between every object you render? Ok? Bad idea? Better to use glPushMarix() / glPopMatrix()?

As for my VBO code...

[code]
bool AhlywoGraphix::BuildVBO(ModelData* Model)
{
glBindBufferARB( GL_ARRAY_BUFFER_ARB, VBO_ID );
GLsizei VBOsize = Model->VertexCount*3*sizeof(float) + Model->NormalCount*3*sizeof(float) + Model->TexCoordCount*2*sizeof(float);
glBufferDataARB( GL_ARRAY_BUFFER_ARB, VBOsize, NULL, GL_STATIC_DRAW_ARB );
if (Model->VertexCount > 0.0)
{
glBufferSubDataARB( GL_ARRAY_BUFFER_ARB, VBO_Offset, Model->VertexCount*3*sizeof(float), Model->VertexData );
Model->VBOVertexOffset = VBO_Offset;
VBO_Offset += Model->VertexCount*3*sizeof(float);
}
if (Model->NormalCount > 0.0)
{
glBufferSubDataARB( GL_ARRAY_BUFFER_ARB, VBO_Offset, Model->NormalCount*3*sizeof(float), Model->NormalData );
Model->VBONormalOffset = VBO_Offset;
VBO_Offset += Model->NormalCount*3*sizeof(float);
}
if (Model->TexCoordCount > 0.0)
{
glBufferSubDataARB( GL_ARRAY_BUFFER_ARB, VBO_Offset, Model->TexCoordCount*2*sizeof(float), Model->TexCoordData );
Model->VBOTexCoordOffset = VBO_Offset;
VBO_Offset += Model->TexCoordCount*2*sizeof(float);
}
return true;
}[/code]

This gets called every time I load a model. As I said before if I load one model it works fine, more than one and nothing works. I'm guessing it has something to do with my glBufferDataARB() call but I can't figure out what. Any suggestions?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this