Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


glLists and pushing/poping help pls[Resolved]


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Gauge   Members   -  Reputation: 122

Like
0Likes
Like

Posted 01 March 2009 - 11:51 PM

So I have this rendering engine and it renders 1 object fine, sometimes 2, however when I get 3 or more it starts freezing and doing all sorts of weird stuff. I have a file that tells my object how to draw itself. when the object tells it to push, I do this push a matrix start a new list draw the peice end the list later on in the code if the command is pop i just pop the matrix Does the placement of pushing and popping matter when using glLists? The reason I do this is because I push matrices on like a torso all the way to the hand, then pop back to the torso and go to the other hand, so on and so forth. So when I rotate the arm say, it rotates the forearm and hand as well. Any help on this is much appreciated, I've been banging my head on a wall and being in Iraq certainly doesn't help my frustration lol. [Edited by - Gauge on March 3, 2009 5:57:58 AM]

Sponsor:

#2 Lord_Evil   Members   -  Reputation: 680

Like
0Likes
Like

Posted 02 March 2009 - 12:07 AM

No, the matrix stack doesn't go into your lists.

What is included are glTranslate, glRotate, glScale, draw calls etc.

You have to do the pushing/popping every time you call the lists.

#3 Gauge   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 March 2009 - 03:36 AM

So I have to push and pop in the right sequence every time I call the list? There is no way to tell openGL when I rotate one list to rotate some other associated lists? like the arm/hand example I used?

Also another question is, if this i true, how does keep track of the stack when you are deleting and adding objects to the draw que. Can you generate matrix lists like you do with display lists and texture lists?

#4 Lord_Evil   Members   -  Reputation: 680

Like
0Likes
Like

Posted 02 March 2009 - 07:09 PM

Well, you could use a tree to represent the object hierarchy, i.e. torso -> arm -> forearm -> hand.

Then you either render that hierarchy pushing the current matrix as you move down and popping as you move up. This would allow you to only use display lists with glTranslate calls and the like embedded in the list. However, you have to keep that exact order for rendering.

Another approach would be to have that tree but you store the complete world transform in each node. Whenever a node is transformed you propagate the changes down the tree. You can do this lazily, i.e. you either call some "recalculate" method after all transformations or set a "dirty" flag and recalculate on retrieval if dirty = true.

This approach allows you to order your objects by render state, texture or whatever you like. When rendering you just push the current matrix (which should be the view transform only), multiply with the current node's world matrix and pop again.

#5 Gauge   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 March 2009 - 08:51 PM

That is exactly what I was planning to do, it's good to know I'm on the right track, however the problem still exists that the object disappears after drawing once and freezes when 3 or more objects are drawn.

I changed my code a little. I send all my objects to a display function. If the object is loaded it just calls the display list associated with it, if not it loads it.

When I load it each group within the object(these are segmented objects) has it's own openGL list GLunit. So I just go group by group and do
groupGLListIndex = glGenList(1);
glNewList(groupCompileIndex, GL_COMPLILE_AND_EXECUTE);
start triangles
draw the object
end triangles
end the list

it does this for all the groups in the object to be loaded. This allows me to animated using Display lists which should run much faster.

for some reason this will execute and draw the first time but when I call the lists for all the groups in an object it won't draw. Currently all my engine does is draw something and move the camera around it.

I'm just banging my head against the well here. Any help is again appreciated. I'll try to get code in here but I'm on an MWR comp to write this because I'm overseas.

Thanks again guys

#6 Lord_Evil   Members   -  Reputation: 680

Like
0Likes
Like

Posted 02 March 2009 - 09:16 PM

Well, without code or at least a video it's hard to tell.

And please, if you manage to post some code, use the source tags.

#7 Gauge   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 March 2009 - 09:40 PM

Here is my "Main" file, it just exists to test my render engine. I didn't write the camera stuff, someone else did. I was going to mess with a camera class once I got the render engine up and running.

I'm sorry in advance for the tabbing. I switch between linux and windows environments to code this. Sometimes the tabbing is out of control, I have recently remedied it by specifying exact spacing for the tab key, but I have not had to to replace all the tabs yet.


#include "render.h"

using namespace std;

bool persp = true;
float ex, ey, ez;
float cx, cy, cz;
float ux, uy, uz;
int xrot, yrot, zrot;
float phi, d, posx, posz;

vector<BaseObject> objects;
render render1;

void Display();
void InitParams();
void KeyPress(unsigned char, int, int);
void MySpecialKeyFunc(int, int, int);

int main(int argc, char* argv[])
{
BaseObject legoMan("LegoPartier_v004.obj", "legoPivot.txt");
objects.push_back(legoMan);

//BaseObject froggy("Froggy_v002.obj", "FroggyPivot.txt");
//objects.push_back(froggy);

//BaseObject pete("peteF.obj", "petePivot.txt");
//objects.push_back(pete);

//BaseObject tom("TomF.obj", "tomPivot.txt");
//objects.push_back(tom);

SDL_Init(SDL_INIT_VIDEO);
glutInit(&argc,argv);
glutInitWindowSize(500, 500);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE);
glutCreateWindow("Levi Beta Render");

InitParams();
render1.Init(GG_MS);

glutDisplayFunc(Display);
glutKeyboardFunc(KeyPress);
glutSpecialFunc(MySpecialKeyFunc);
glutMainLoop();
SDL_Quit();

render1.FreeLists(objects);
objects.clear();

return 0;
}

void Display()
{
ex = posx;
ez = posz;
cx = posx + d * sin(phi * M_PI / 180.0);
cz = posz + d * cos(phi * M_PI / 180.0);

glLoadIdentity();
gluLookAt(ex, ey, ez, cx, cy, cz, ux, uy, uz);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glRotatef(xrot, 1, 0, 0);
glRotatef(yrot, 0, 1, 0);
glRotatef(zrot, 0, 0, 1);

glTranslatef(0, 3.5, 0);

render1.Display(objects);

glutSwapBuffers();
}

void InitParams()
{
ex = -10.1;
ey = 5.9;
ez = 2;
cx = 0;
cy = 6.3;
cz = 0;
ux = 0;
uy = 1;
uz = 0;
phi = 180;
posx = .1;
posz = 30;
d = 3;
xrot = yrot = zrot = 0;
}

void KeyPress(unsigned char c, int x, int y)
{
switch(c)
{
case 'q':
{
render1.FreeLists(objects);
exit(0);
}
case 'n': InitParams(); break;
case 'u': cy += cy * .1; break;
case 'd': cy -= cy * .1; break;
case 'x': xrot += 5; break;
case 'y': yrot += 5; break;
case 'z': zrot += 5; break;
case 'X': xrot += 5; break;
case 'Y': yrot += 5; break;
case 'Z': zrot += 5; break;
case 'f':
{
posx += d * sin(phi*M_PI/180.0) * .1;
posz += d * cos(phi*M_PI/180.0) * .1;
break;
}
case 'F':
{
posx -= d * sin(phi*M_PI/180.0) * .1;
posz -= d * cos(phi*M_PI/180.0) * .1;
break;
}
case 'p': phi -= 1; break;
case 'P': phi += 1; break;
case 'c': xrot -= 5; break;
}
glutPostRedisplay();
}

void MySpecialKeyFunc(int c, int x, int y)
{
switch(c)
{
case GLUT_KEY_UP:
{
posx += d * sin(phi*M_PI/180.0) * .1;
posz += d * cos(phi*M_PI/180.0) * .1;
break;
}
case GLUT_KEY_DOWN:
{
posx -= d * sin(phi*M_PI/180.0) * .1;
posz -= d * cos(phi*M_PI/180.0) * .1;
break;
}
case GLUT_KEY_RIGHT:
{
phi -= 1;
break;
}
case GLUT_KEY_LEFT:
{
phi += 1;
break;
}
}
glutPostRedisplay();
}




here is my render class, I wrote all of this.


#include "render.h"

render::render()
{
theta = 47;
}

render::~render()
{
}

void render::LoadObject(vector<BaseObject>::iterator& tempObject)
{
vector<point>::iterator v = tempObject->GetVBegin();
vector<point>::iterator vn = tempObject->GetVnBegin();
vector<uvPoint>::iterator vt = tempObject->GetVtBegin();

int y = 0;
bool loadVT = false;

for(vector<group>::iterator x = tempObject->GetGroupsBegin(); x != tempObject->GetGroupsEnd() ; x++)
{
for(int i = 0; i < x->faces.size() ; i++)
{
/*if(i == 0)
{
SetUpTexture(tempObject.GetMaterialLoc(), x->materials[y].materialName, loadVT);
}
else if(i == x->materials[y].polyIndex)
{
y++;
SetUpTexture(tempObject.GetMaterialLoc(), x->materials[y].materialName, loadVT);
}*/


/*if(loadVT)
{
glBindTexture(GL_TEXTURE_2D, texture);
}*/

x->groupCompileIndex = glGenLists(1);
glNewList(x->groupCompileIndex, GL_COMPILE_AND_EXECUTE);
glBegin(GL_TRIANGLES);

if(loadVT)
{
glTexCoord2f(vt[x->faces[i].vtIndex[0]-1].x, vt[x->faces[i].vtIndex[0]-1].y);
}
glNormal3f(vn[x->faces[i].vnIndex[0]-1].x, vn[x->faces[i].vnIndex[0]-1].y, vn[x->faces[i].vnIndex[0]-1].z);
glVertex3f(v[x->faces[i].vIndex[0]-1].x, v[x->faces[i].vIndex[0]-1].y, v[x->faces[i].vIndex[0]-1].z);

if(loadVT)
{
glTexCoord2f(vt[x->faces[i].vtIndex[1]-1].x, vt[x->faces[i].vtIndex[1]-1].y);
}
glNormal3f(vn[x->faces[i].vnIndex[1]-1].x, vn[x->faces[i].vnIndex[1]-1].y, vn[x->faces[i].vnIndex[1]-1].z);
glVertex3f(v[x->faces[i].vIndex[1]-1].x, v[x->faces[i].vIndex[1]-1].y, v[x->faces[i].vIndex[1]-1].z);

if(loadVT)
{
glTexCoord2f(vt[x->faces[i].vtIndex[2]-1].x, vt[x->faces[i].vtIndex[2]-1].y);
}
glNormal3f(vn[x->faces[i].vnIndex[2]-1].x, vn[x->faces[i].vnIndex[2]-1].y, vn[x->faces[i].vnIndex[2]-1].z);
glVertex3f(v[x->faces[i].vIndex[2]-1].x, v[x->faces[i].vIndex[2]-1].y, v[x->faces[i].vIndex[2]-1].z);

glEnd();
glEndList();
}
}
}

/*void render::SetUpTexture(string fileName, string materialName, bool& loadVT)
{
if(!tFactory.TextureLoaded(materialName));
{
tFactory.LoadTexture(fileName, materialName);
}
glBindTexture(GL_TEXTURE_2D, tFactory.GetTexture(materialName));
loadVT = tFactory.IsUvMap(materialName);
}*/


void render::LightSetup()
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
}

void render::SetupBlending(int& bType) const //antialiasing
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

switch(bType)
{
case GG_AA_X2:
{
glEnable(GL_POLYGON_SMOOTH);
glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
}
case GG_AA_X4:
{
glEnable(GL_POLYGON_SMOOTH);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
}
case GG_MS:
{
glEnable(GL_MULTISAMPLE);
}
}
}

void render::Init(int bType)
{
glEnable(GL_TEXTURE_2D);

SetupBlending(bType);

glMatrixMode(GL_PROJECTION);
gluPerspective(theta, 1, .9, 500);
glMatrixMode(GL_TEXTURE);
glRotatef(180.0, 1.0, 0.0, 0.0); //Flips textures due to how SDL loads them.
glMatrixMode(GL_MODELVIEW);
glClearColor(0.0, 0.0, 0.0, 0.0);
glFrontFace(GL_CCW);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
LightSetup();
}

void render::Display(vector<BaseObject>& objects)
{
for(vector<BaseObject>::iterator i = objects.begin() ; i != objects.end() ; i++)
{
if(!i->Loaded())
{
LoadObject(i);
i->ChangeLoadState(true);
}
else
{
for(vector<group>::iterator x = i->GetGroupsBegin() ; x != i->GetGroupsEnd() ; x++)
{
glCallList(x->groupCompileIndex);
}
}
}
}

void render::FreeLists(vector<BaseObject>& objects)
{
for(vector<BaseObject>::iterator i = objects.begin() ; i != objects.end() ; i++)
{
for(vector<group>::iterator x = i->GetGroupsBegin() ; x != i->GetGroupsEnd() ; x++)
{
glDeleteLists(x->groupCompileIndex, 1);
}
}
//tFactory.DeleteAll();
}




I removed all texturing code, I know it's messed up and I know how I'm going to fix it, right now I just want to get drawing on the screen working.

#8 Lord_Evil   Members   -  Reputation: 680

Like
0Likes
Like

Posted 02 March 2009 - 11:33 PM

I had only a quick look at your code but there are some points I noticed:

1. You generate a display list for each triangle -> not good, generate one per (sub)object
2. The transformation code (along with glPush etc.) is missing, so I can't tell you anything about that.
3. You enable lighting but I didn't see any material setup (or GL_COLOR_MATERIAL) -> objects will be black/unlit
4. Are you sure your polygons are wound correctly? If not try disabling backface culling.

I'm still unsure of what results you are getting now. A screenshot or more thorough explanation would be helpful [smile].

#9 Gauge   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 March 2009 - 11:43 PM

Quote:
Original post by Lord_Evil
I had only a quick look at your code but there are some points I noticed:

1. You generate a display list for each triangle -> not good, generate one per (sub)object
2. The transformation code (along with glPush etc.) is missing, so I can't tell you anything about that.
3. You enable lighting but I didn't see any material setup (or GL_COLOR_MATERIAL) -> objects will be black/unlit
4. Are you sure your polygons are wound correctly? If not try disabling backface culling.

I'm still unsure of what results you are getting now. A screenshot or more thorough explanation would be helpful [smile].


1. you are absolutely correct and I feel retarded now.
2. I took it out once I realized I wasn't drawing and texturing correctly. I like to move in steps.
3.The light actually works, I only know this because it has worked before I s tarted changing things. But you are probably correct as I am an openGL noob and I will look into it more.
4. Yea I'm sure. Again I know this because I had it drawing before, although incorrectly.

I'll move the list generation and start/stop and see if that helps, I'll also look at the lighting.

I really appreciate all your help.

#10 Gauge   Members   -  Reputation: 122

Like
0Likes
Like

Posted 02 March 2009 - 11:57 PM

Moving where the lists are generated and started resolved the drawing problem. I have a problem exiting the program but I'm sure with some thought I can figure it out.

Thanks I'm going to let this one die for now ^_^ thank you so much.

#11 Lord_Evil   Members   -  Reputation: 680

Like
0Likes
Like

Posted 03 March 2009 - 12:55 AM

You're welcome




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS