3 Replies - 968 Views - Last Post: 11 September 2014 - 04:22 PM Rate Topic: -----

#1 UG Cyber   User is offline

  • D.I.C Addict

Reputation: 36
  • View blog
  • Posts: 611
  • Joined: 24-July 08

OpenGL issue or Code Issue...not sure

Posted 10 September 2014 - 05:34 PM

Sorry guys, but i'm really puzzled about this one. Its the same game and its coming along nicely but now im running into another issue and i'm not sure if its my code, the compiler/IDE or openGL itself. I will try to explain it as best as i can.

I was going to send my game out to a few friends so they can play around with it and give me some suggestions on how they think I can improve the game, so i compiled a "Release" version of the game. Then i put the executable in a seperate directory and placed all other directories (for the obj and audio files) in the correct places. When i started the executable outside of Code::Blocks, it would only draw the map and explosions(the explosions were handled through GLUT api). The character and the bombs would not show. When I run it through the Code::Blocks run button, everything would appear as it should.

I did some further research and found that everything would appear when i called cgl.objDraw(ObjectLoader, int) which would only draw the object indexed by the second argument. The code for that function was copied from cgl.objDraw(ObjectLoader) which would draw all objects within that structure.

again, everything works perfectly when I start the program through Code::Blocks
Here are the code segments in question
cgl.objDraw()
void        CGL::objDraw(ObjLoader obj){
    glPushMatrix();
    glTranslated(obj.pos.x, obj.pos.y, obj.pos.z);
    glRotated(obj.pos.xrot, 1, 0, 0);
    glRotated(obj.pos.yrot, 0, 1, 0);
    glRotated(obj.pos.zrot, 0, 0, 1);
    for(int o = 0; o < obj.objCount; o++){
        tex.SetActiveTexture(obj.obj[o].imgIndex);
        glPushMatrix();
        glTranslated(obj.obj[o].pos.x,obj.obj[o].pos.y,obj.obj[o].pos.z);
        glRotated(obj.obj[o].pos.xrot, 1, 0, 0);
        glRotated(obj.obj[o].pos.yrot, 0, 1, 0);
        glRotated(obj.obj[o].pos.zrot, 0, 0, 1);
        glBegin(GL_TRIANGLES);
        for(int f = 0; f < obj.obj[o].TotalFaceCount; f++){
            for(int i = 0; i < 3; i++){
                glTexCoord2d(obj.uv_vert[obj.obj[o].fmap[f].uvI[i]].x, obj.uv_vert[obj.obj[o].fmap[f].uvI[i]].y);
                glVertex3f(obj.vert[obj.obj[o].fmap[f].vI[i]].x, obj.vert[obj.obj[o].fmap[f].vI[i]].y, obj.vert[obj.obj[o].fmap[f].vI[i]].z);
            }
        }
        glEnd();
        glPopMatrix();
    }
   glPopMatrix();

}
void        CGL::objDraw(ObjLoader obj, int oi){
    tex.SetActiveTexture(obj.obj[oi].imgIndex);
    glBegin(GL_TRIANGLES);
    for(int f = 0; f < obj.obj[oi].TotalFaceCount; f++){
        for(int i = 0; i < 3; i++){
            glTexCoord2d(obj.uv_vert[obj.obj[oi].fmap[f].uvI[i]].x, obj.uv_vert[obj.obj[oi].fmap[f].uvI[i]].y);
            glVertex3f(obj.vert[obj.obj[oi].fmap[f].vI[i]].x, obj.vert[obj.obj[oi].fmap[f].vI[i]].y, obj.vert[obj.obj[oi].fmap[f].vI[i]].z);
        }
    }
    glEnd();
}


I know its a hard code to follow
int i indexes the texture coordinates with the vertices of the triangle.
main.cpp - display function
void Display(void){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

        glTranslatef(0,-1.0, cRadius);
        glRotated(player.current.xrot, 1, 0, 0);
        for(int i = 0; i < claptrap.objCount; i++){
            cgl.objDraw(claptrap, i); //<-This will appear in both cases
        }
        //cgl.objDraw(claptrap); <- Will not appear when ran outside of code::blocks
        glRotated(player.current.yrot, 0, 1, 0);
        glTranslated(-player.current.x, 0, -player.current.z);

        //cgl.objDraw(Map);
        for(int i = 0; i < Map.objCount; i++){
            if(i != breakBox){
                cgl.objDraw(Map, i);
            }
        }

        drawBombs();
        drawBoxes();
        //Menu drawing stuff, i left it out of the post.
}


Im running Windows7/Code::Blocks with MingW/ OpenGL/GLUT/
If you need anymore information or code, just let me know.

Is This A Good Question/Topic? 0
  • +

Replies To: OpenGL issue or Code Issue...not sure

#2 Kain6622   User is offline

  • D.I.C Regular

Reputation: 19
  • View blog
  • Posts: 268
  • Joined: 18-March 10

Re: OpenGL issue or Code Issue...not sure

Posted 10 September 2014 - 07:28 PM

Hi UG Cyber, I've not done OpenGL in a long time but from looking at your code and if i'm right in thinking that the first objDraw(ObjLoader obj) your not getting everything displaying in the final build and the second you are in both compiler and executable, the only difference is some extra calls to the matrix stack:

void CGL::objDraw(ObjLoader obj){
glPushMatrix();
glTranslated(obj.pos.x, obj.pos.y, obj.pos.z);
glRotated(obj.pos.xrot, 1, 0, 0);
glRotated(obj.pos.yrot, 0, 1, 0);
glRotated(obj.pos.zrot, 0, 0, 1);

for(int o = 0; o < obj.objCount; o++){
tex.SetActiveTexture(obj.obj[o].imgIndex);
glPushMatrix();
glTranslated(obj.obj[o].pos.x,obj.obj[o].pos.y,obj.obj[o].pos.z);
glRotated(obj.obj[o].pos.xrot, 1, 0, 0);
glRotated(obj.obj[o].pos.yrot, 0, 1, 0);
glRotated(obj.obj[o].pos.zrot, 0, 0, 1);
glBegin(GL_TRIANGLES);
for(int f = 0; f < obj.obj[o].TotalFaceCount; f++){
for(int i = 0; i < 3; i++){
glTexCoord2d(obj.uv_vert[obj.obj[o].fmap[f].uvI[i]].x, obj.uv_vert[obj.obj[o].fmap[f].uvI[i]].y);
glVertex3f(obj.vert[obj.obj[o].fmap[f].vI[i]].x, obj.vert[obj.obj[o].fmap[f].vI[i]].y, obj.vert[obj.obj[o].fmap[f].vI[i]].z);
}
}
glEnd();
glPopMatrix();
}
glPopMatrix();

}

Which is not present in the second (working) version, to me that would imply that rather than the objects not showing as such, they have been miss translated in the matrix stack to somewhere out of the player view. Is there any reason you have those transformations in the first function? what purpose are they to serve?

Edit: if those transformations do have a meaning, remember that translation before rotation has a different effect to rotation then translation.

Apologies to Admin for not using the code blocks here, couldn't highlight the areas I wanted in it.

This post has been edited by Kain6622: 10 September 2014 - 07:32 PM

Was This Post Helpful? 1
  • +
  • -

#3 UG Cyber   User is offline

  • D.I.C Addict

Reputation: 36
  • View blog
  • Posts: 611
  • Joined: 24-July 08

Re: OpenGL issue or Code Issue...not sure

Posted 11 September 2014 - 03:19 AM

It allows me to translate objects with out causing issues with other objects.

The Structure ObjLoader loads an entire obj file, in which could have many objects in the one file. In order to rotate them all without constant calls to glRotate(), i can set the rotation in ObjLoader and just do it once.

I'll poke around with it and see if i can't get a different result.
Was This Post Helpful? 0
  • +
  • -

#4 UG Cyber   User is offline

  • D.I.C Addict

Reputation: 36
  • View blog
  • Posts: 611
  • Joined: 24-July 08

Re: OpenGL issue or Code Issue...not sure

Posted 11 September 2014 - 04:22 PM

I do believe your right. I'm not sure why or how, but your right. The issue is with the glPushMatrix() glPopMatrix(); I took those out and got crazy output while trying to play the game. My character displayed facing the wrong way, w turned into strafe and so forth...

I just took out the ObjLoader position as a whole and placed the position changes in each individual object... seems to work fine now.

Any ideas on why it wouldn't mess up when i ran the program through Code::Blocks??
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1