[Solved]anyone got a sample code using vertex arrays and glulookat?

Started by
3 comments, last by SonOfSparda 13 years, 6 months ago
Hi,

I got a display issue wich make my glvertex models follow the glulook at while they shouldn't. All the source code that i found about displaying vertex arrays are using a single vertex array and no glulookat. So that would be kind if someone can show me his routine to draw his vertex arrays, like when you do the load identity, when you place the glulookat, how you place the array within the context...

KTHXBYE

[Edited by - SonOfSparda on October 17, 2010 4:22:05 PM]
Advertisement
Broadly speaking.. for any given camera viewing the scene, start rendering from it's perspective by:

// camera// Configure the projection matrix glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(fov, aspect_ratio, near_clip_plane, far_clip_plane);// Prepare the modelview matrixglMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(position.x(), position.y(), position.z(), position.x()+forward.x(), position.y()+forward().y(), position.z()+forward.z(), up.x(), up.y(), up.z());// object rendering// Then sometime later during rendering your individual objects, you need to transform their vertices from object space into world space:glPushMatrix()glMultMatrixf(obj->obj_matrix().mat44); // This is a 4x4 matrix representing the object's orientation and position in world space. How you derive this is up to you... // render object hereglBegin(GL_POINTS);glVertex3f(0,0,0);glEnd();glPopMatrix();


HTH

edit: Of course replace the glBegin/glEnd() with your vertex array rendering routine.
- Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.
Although in addition, I suggest you read the topic (below this at the moment) regarding how matrix stacks are obsolete now.
- Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.
Ok thanks so we are good on this one

then i display my elements so:
Quote:
for(int i=0; i< Scenery.size(); i++) // i display my scenery elements wich are display lists
{
glPushMatrix();

glTranslated(Scenery->getPos().x,0,Scenery->getPos().y);
Scenery->display();
glPopMatrix();
}



for(int i=0; i< Characters.size(); i++)// here comes the tricky part, i display my charachters wich i turned to vertex arrays recently
{
glPushMatrix();

glTranslated(Characters->getPos().x,-15,Characters->getPos().y);//placing
glScaled(0.2,0.2,0.2);//some adjustements
glRotated(-90,1,0,0);

Characters->display(); // do the regulars glEnable, drawelements and so on, not my code in fact proven to be working with a single model and no lookat
glPopMatrix();
}


Edit: for your over answer i don't know much about opengl 3 in fact nothing at all, i prefer staying on opengl2 some more just the time i become more confident with 3D programming and get the basics.
Yay got it: in the display function, there was an other set of glEnable / glDisable DEPTH_TEST.

I'll try to make the thread solved, dunno if it's posible. Thank you guys BTW.

This topic is closed to new replies.

Advertisement