newbie questionz
hi all,
i''m a little wet behind the ears when it comes to openGL programming and have a few questions.
1.
I have made a Model class, it contains lots of points and triangles relating to the points. the drawing is done using the model''s GLDraw() function.
i also have a DrawScene() function in my game wrapper which basically does this...
DrawScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
view.update();
for (int i = 0; i < NUMMODELS; i++)
models.GLDraw();
}
I am having the age-old problem of the viewpoint bieng always at the origin of the world and wondered if theres an easy way round all this for my above code to work.
2.
Whilst browsing the forums i have come across the glCallList() function. I think it might be able to replace my Model GLDraw() function but i''m not sure as to what it does exactly.. can anyone shed any light on it and how i would go about using it?
Thanks in advance
mod
1.
Use some kind of camera system like this:
glLoadIdentity();
glRotatef(-camera.x_angle,1.0f,0.0f,0.0f);
glRotatef(-camera.y_angle,0.0f,1.0f,0.0f);
glRotatef(-camera.z_angle,0.0f,0.0f,1.0f);
glTranslatef(-camera.x, -camera.y,-camera.z);
model.GLDraw();
2.
id=glGenLists(1);
glNewList(id, GL_COMPILE);
model.GLDraw();
glEndList();
// Nothing is rendered but when you call
glCallList(id); // the model is rendered to the screen...
[edited by - circuit on April 30, 2002 4:09:54 AM]
Use some kind of camera system like this:
glLoadIdentity();
glRotatef(-camera.x_angle,1.0f,0.0f,0.0f);
glRotatef(-camera.y_angle,0.0f,1.0f,0.0f);
glRotatef(-camera.z_angle,0.0f,0.0f,1.0f);
glTranslatef(-camera.x, -camera.y,-camera.z);
model.GLDraw();
2.
id=glGenLists(1);
glNewList(id, GL_COMPILE);
model.GLDraw();
glEndList();
// Nothing is rendered but when you call
glCallList(id); // the model is rendered to the screen...
[edited by - circuit on April 30, 2002 4:09:54 AM]
thanks dude.. that cleared up the 2nd question but i fekked up and didnt ask the 1st question right i''m thinkin...
heres what i should have written.... there is an array of models called models
Heres the view update function..
readin sum forums i noticed all this push n pop matrices and i''m sadly very confused
thx again,
mod
heres what i should have written.... there is an array of models called models
DrawScene(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();ViewUpdate();for (int i = 0; i < NUMMODELS; i++)models->GLDraw();}
Heres the view update function..
ViewUpdate(){ glRotatef(rotation.x,1.0f,0,0); glRotatef(rotation.y,0,1.0f,0); glTranslatef(position.x, position.y], position.z);}
readin sum forums i noticed all this push n pop matrices and i''m sadly very confused
thx again,
mod
well push and pop are quite easy..
you push the current matrix
you manipulate the matrix (rotate, translate etc)
you pop it back to the state it was before
that means:
glLoadIdentity();
setupview();
for every model {
glPushMatrix();
glTranslate(model.x,model.y,model.z);
//possibly some rotate and scale as well..
glBegin(GL_TRIANGLES); {
glVertex(...);
} glEnd();
}
and, cause you design it bether, its in the modelclass..
Model::GLDraw() {
glPushMatrix(); {
glTranslatef(x,y,z);
DrawMesh();
}glPopMatrix();
}
that way your models are free.. everyone has its own position stored, and they are drawn at this very position..
nice, not?
second question:
i never use lists.. dunno, i don''t like static stuff..
if your meshes have animations, you cannot use lists that easy anymore..
"take a look around" - limp bizkit
www.google.com
you push the current matrix
you manipulate the matrix (rotate, translate etc)
you pop it back to the state it was before
that means:
glLoadIdentity();
setupview();
for every model {
glPushMatrix();
glTranslate(model.x,model.y,model.z);
//possibly some rotate and scale as well..
glBegin(GL_TRIANGLES); {
glVertex(...);
} glEnd();
}
and, cause you design it bether, its in the modelclass..
Model::GLDraw() {
glPushMatrix(); {
glTranslatef(x,y,z);
DrawMesh();
}glPopMatrix();
}
that way your models are free.. everyone has its own position stored, and they are drawn at this very position..
nice, not?
second question:
i never use lists.. dunno, i don''t like static stuff..
if your meshes have animations, you cannot use lists that easy anymore..
"take a look around" - limp bizkit
www.google.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement