Sign in to follow this  
SonOfSparda

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

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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 matrix
glMatrixMode(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 here
glBegin(GL_POINTS);
glVertex3f(0,0,0);
glEnd();

glPopMatrix();





HTH

edit: Of course replace the glBegin/glEnd() with your vertex array rendering routine.

Share this post


Link to post
Share on other sites
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[i]->getPos().x,0,Scenery[i]->getPos().y);
Scenery[i]->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[i]->getPos().x,-15,Characters[i]->getPos().y);//placing
glScaled(0.2,0.2,0.2);//some adjustements
glRotated(-90,1,0,0);

Characters[i]->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.

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