Sign in to follow this  
SHOKWAV

OpenGL Image Doesn't Display?

Recommended Posts

Hi, I created a simple class to make drawing on OpenGL easier. I was successfull, until I get into rotation.... now my class won't even show! Am I doing something wrong with matrixs? (It compiles fine, of course, and OpenGL doesn't error...)

[b][size="2"][color="#7f0055"][size="2"][color="#7f0055"][left]class[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]primitive[/color][/size][/color][/size][size="2"]{[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]typedef[/b][/color][/size][/color][/size][size="2"] std::[/size][size="2"][color="#005032"][size="2"][color="#005032"]vector[/color][/size][/color][/size][size="2"]<[/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"]> [/size][size="2"][color="#005032"][size="2"][color="#005032"]v[/color][/size][/color][/size][size="2"];[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]typedef[/b][/color][/size][/color][/size][size="2"] std::[/size][size="2"][color="#005032"][size="2"][color="#005032"]list[/color][/size][/color][/size][size="2"]<[/size][size="2"][color="#005032"][size="2"][color="#005032"]v[/color][/size][/color][/size][size="2"]> [/size][size="2"][color="#005032"][size="2"][color="#005032"]v_dat[/color][/size][/color][/size][size="2"];[/left]
[left][/size][size="2"][color="#005032"][size="2"][color="#005032"]v_dat[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]vertex_data[/color][/size][/color][/size][size="2"];[/left]
[left][/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][3];[/left]
[left][/size][size="2"][color="#005032"][size="2"][color="#005032"]GLclampf[/color][/size][/color][/size][size="2"] [/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][2];[/left]
[/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"][left]public[/b][/color][/size][/color][/size][size="2"]:[/left]
[left][b]primitive[/b]([/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLclampf[/color][/size][/color][/size][size="2"] r=1.0f, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLclampf[/color][/size][/color][/size][size="2"] g=0.0f, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLclampf[/color][/size][/color][/size][size="2"] b=0.0f, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLclampf[/color][/size][/color][/size][size="2"] angle=0.0f, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] rotx=0.0f,[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] roty=0.0f, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] rotz=0.0f){[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][0]=angle;[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][1]=rotx;[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][2]=roty;[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][3]=rotz;[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][0]=r;[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][1]=g;[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][2]=b;[/left]
[left]}[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]void[/b][/color][/size][/color][/size][size="2"] [b]addVertex[/b]([/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] x, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] y, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] z){[/left]
[left][/size][size="2"][color="#005032"][size="2"][color="#005032"]v[/color][/size][/color][/size][size="2"] vertex;[/left]
[left]vertex.push_back(x);[/left]
[left]vertex.push_back(y);[/left]
[left]vertex.push_back(z);[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]vertex_data[/color][/size][/color][/size][size="2"].push_back(vertex);[/left]
[left]}[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]void[/b][/color][/size][/color][/size][size="2"] [b]draw[/b]([/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]bool[/b][/color][/size][/color][/size][size="2"] swap=[/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]true[/b][/color][/size][/color][/size][size="2"]){[/left]
[left]std::[/size][size="2"][color="#005032"][size="2"][color="#005032"]list[/color][/size][/color][/size][size="2"]<[/size][size="2"][color="#005032"][size="2"][color="#005032"]v[/color][/size][/color][/size][size="2"]>::[/size][size="2"][color="#005032"][size="2"][color="#005032"]const_iterator[/color][/size][/color][/size][size="2"] i;[/left]
[left][/size][b][size="2"][color="#642880"][size="2"][color="#642880"]glClear[/b][/color][/size][/color][/size][size="2"](GL_COLOR_BUFFER_BIT);[/left]
[left][/size][b][size="2"][color="#642880"][size="2"][color="#642880"]glPushMatrix[/b][/color][/size][/color][/size][size="2"]();[/size][size="2"][color="#3f7f5f"][size="2"][color="#3f7f5f"]//push matrix stack down and save the current matrix[/left]
[/color][/size][/color][/size][size="2"][left][/size][b][size="2"][color="#642880"][size="2"][color="#642880"]glRotatef[/b][/color][/size][/color][/size][size="2"]([/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][0], [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][1], [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][2], [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][3]);[/left]
[left][/size][b][size="2"][color="#642880"][size="2"][color="#642880"]glBegin[/b][/color][/size][/color][/size][size="2"](GL_POLYGON);[/left]
[left][/size][b][size="2"][color="#642880"][size="2"][color="#642880"]glColor3f[/b][/color][/size][/color][/size][size="2"]([/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][0], [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][1], [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][2]);[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]for[/b][/color][/size][/color][/size][size="2"](i=[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]vertex_data[/color][/size][/color][/size][size="2"].begin(); i!=[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]vertex_data[/color][/size][/color][/size][size="2"].end(); i++){[/left]
[left][/size][b][size="2"][color="#642880"][size="2"][color="#642880"]glVertex3f[/b][/color][/size][/color][/size][size="2"](i->at(0), i->at(1), i->at(2));[/size][size="2"][color="#3f7f5f"][size="2"][color="#3f7f5f"]//i* is a vertex object[/left]
[/color][/size][/color][/size][size="2"][left]}[/left]
[left][/size][b][size="2"][color="#642880"][size="2"][color="#642880"]glEnd[/b][/color][/size][/color][/size][size="2"]();[/left]
[left][/size][b][size="2"][color="#642880"][size="2"][color="#642880"]glPopMatrix[/b][/color][/size][/color][/size][size="2"]();[/size][size="2"][color="#3f7f5f"][size="2"][color="#3f7f5f"]//get the old matrix[/left]
[/color][/size][/color][/size][size="2"][left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]if[/b][/color][/size][/color][/size][size="2"](swap){[/left]
[left][/size][b][size="2"][color="#642880"][size="2"][color="#642880"]SDL_GL_SwapBuffers[/b][/color][/size][/color][/size][size="2"]();[/left]
[left]}[/left]
[left]}[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]void[/b][/color][/size][/color][/size][size="2"] [b]flush[/b](){[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]if[/b][/color][/size][/color][/size][size="2"](![/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]vertex_data[/color][/size][/color][/size][size="2"].empty()){[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]vertex_data[/color][/size][/color][/size][size="2"].clear();[/left]
[left]}[/left]
[left]}[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]void[/b][/color][/size][/color][/size][size="2"] [b]translate[/b]([/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] offx, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] offy, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] offz){[/left]
[left]std::[/size][size="2"][color="#005032"][size="2"][color="#005032"]list[/color][/size][/color][/size][size="2"]<[/size][size="2"][color="#005032"][size="2"][color="#005032"]v[/color][/size][/color][/size][size="2"]>::[/size][size="2"][color="#005032"][size="2"][color="#005032"]iterator[/color][/size][/color][/size][size="2"] i;[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]for[/b][/color][/size][/color][/size][size="2"](i=[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]vertex_data[/color][/size][/color][/size][size="2"].begin(); i != [/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]vertex_data[/color][/size][/color][/size][size="2"].end(); i++){[/left]
[left]i->at(0)=i->at(0)+(offx);[/left]
[left]i->at(1)=i->at(1)+(offy);[/left]
[left]i->at(2)=i->at(2)+(offz);[/left]
[left]}[/left]
[left]}[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]void[/b][/color][/size][/color][/size][size="2"] [b]rotate[/b]([/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] angle, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] x, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] y, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLfloat[/color][/size][/color][/size][size="2"] z){[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][0]=angle;[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][1]=x;[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][2]=y;[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]this[/b][/color][/size][/color][/size][size="2"]->[/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]rotate_data[/color][/size][/color][/size][size="2"][3]=z;[/left]
[left]}[/left]
[left][/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]void[/b][/color][/size][/color][/size][size="2"] [b]colors[/b]([/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLclampf[/color][/size][/color][/size][size="2"] r, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLclampf[/color][/size][/color][/size][size="2"] g, [/size][b][size="2"][color="#7f0055"][size="2"][color="#7f0055"]const[/b][/color][/size][/color][/size][size="2"] [/size][size="2"][color="#005032"][size="2"][color="#005032"]GLclampf[/color][/size][/color][/size][size="2"] b){[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][0]=r;[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][1]=g;[/left]
[left][/size][size="2"][color="#0000c0"][size="2"][color="#0000c0"]color_data[/color][/size][/color][/size][size="2"][2]=b;[/left]
[left]}[/left]
};

[/size]

Share this post


Link to post
Share on other sites
[font=arial, verdana, tahoma, sans-serif][size=2]make sure to call glLoadIdentity() somewhere. Try replacing your rotate with that and make sure your image shows up.

What axis are you rotating on anyway and if its a simple quad (unclosed mesh), you need to disable back face culling.[/size][/font]

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