Can see inside box faces, not outside

Started by
11 comments, last by chbfiv 20 years, 6 months ago
Im working on my Mesh class atm for my win32 open engine. my current problem is that when i render a cube from my Mesh class, I only see in inside of the box. I don''t have any lighting set up, but do I need to fix my normals even when im not using lighting?
-BourkeIV
Advertisement
Turn culling off...
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
Or flip the culling. Are you using DirectX or OpenGL?

How appropriate. You fight like a cow.
I did just turned it on, lol. I'm using OpenGL. bah

Edit:
glEnable(GL_CULL_FACE);

I took that out and it still does the same thing. Does it have todo with the order I draw the triangles that make the box?

[edited by - chbfiv on October 6, 2003 10:41:59 PM]
-BourkeIV
In that case, you will want to look at glCullFace.

How appropriate. You fight like a cow.
Are you drawing the triangles in a counterclockwise direction?
quote:Original post by chbfiv
Edit:
glEnable(GL_CULL_FACE);

I took that out and it still does the same thing. Does it have todo with the order I draw the triangles that make the box?

Just getting rid of that line won''t necessarily take off culling. In order to make sure it''s turned off you need to do:

glDisable(GL_CULL_FACE);

The order you define the triangle vertices in is important. OpenGL determines what to cull based on whether you define your vertices in a clockwise or counterclockwise manner. You can change this by doing:

glCullFace(GL_CW);

for clockwise or:

glCullFace(GL_CCW);

for counterclockwise. You may want to try both of these culling modes, it doesn''t really matter what winding you use as long as everything you''re rendering is consistent.
I don't really have an order to fillinf in my box, is that the problem?

opengl.cpp redraw funtion
Mesh tmpMesh; //create mesh objecttmpMesh.box(25); //for testing, fill in a boxvoid  OpenGL::redraw(void) {	GLfloat w = (GLfloat)glutGet(GLUT_WINDOW_WIDTH);	GLfloat h = (GLfloat)glutGet(GLUT_WINDOW_HEIGHT);	glLoadIdentity();	gluPerspective(100.0,w/h,0,1000);        static float rotateBy=0;	rotateBy+=0.5;		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glMatrixMode(GL_MODELVIEW);		glPushMatrix();		glTranslatef(0,0,-50);		glRotatef(rotateBy,1,1,0);			push();		glPopMatrix();		glutSwapBuffers();	glutPostRedisplay();}void  OpenGL::st_redraw(void) {		OpenGLPtr->redraw(); }int OpenGL::push() {	   	tmpMesh.draw();return(0);}mesh.cpp   void Mesh::draw() {  for(int i=0; i < num_faces; i++) {	glBegin(GL_TRIANGLES);		glVertex3f(pFaces[i].a.x,pFaces[i].a.y,pFaces[i].a.z);		glVertex3f(pFaces[i].b.x,pFaces[i].b.y,pFaces[i].b.z);		glVertex3f(pFaces[i].c.x,pFaces[i].c.y,pFaces[i].c.z);	glEnd();  }}void Mesh::box(GLfloat size) {		    // fill vertices	pVertices = new vertex[8];	num_vertices = 8;	for(int i=0;i < num_vertices;i++) {		pVertices[i].x = 0.0f;		pVertices[i].y = 0.0f;		pVertices[i].z = 0.0f;		pVertices[i].r = 1.0f;		pVertices[i].g = 1.0f;		pVertices[i].b = 1.0f;		}	pVertices[1].x = size;	pVertices[2].x = size;	pVertices[2].z = size;	pVertices[3].z = size;	pVertices[4].y = size;	pVertices[5].x = size;	pVertices[5].y = size;	pVertices[6].x = size;	pVertices[6].z = size;	pVertices[6].y = size;	pVertices[7].z = size;	pVertices[7].y = size;	// fill faces	pFaces = new face[12];	num_faces = 12;	pFaces[0].a = pVertices[0];	pFaces[0].b = pVertices[1];	pFaces[0].c = pVertices[2];	pFaces[1].a = pVertices[0];	pFaces[1].b = pVertices[2];	pFaces[1].c = pVertices[3];	pFaces[2].a = pVertices[4];	pFaces[2].b = pVertices[5];	pFaces[2].c = pVertices[6];	pFaces[3].a = pVertices[4];	pFaces[3].b = pVertices[6];	pFaces[3].c = pVertices[7];	pFaces[4].a = pVertices[0];	pFaces[4].b = pVertices[3];	pFaces[4].c = pVertices[4];	pFaces[5].a = pVertices[3];	pFaces[5].b = pVertices[7];	pFaces[5].c = pVertices[4];	pFaces[6].a = pVertices[0];	pFaces[6].b = pVertices[4];	pFaces[6].c = pVertices[1];	pFaces[7].a = pVertices[1];	pFaces[7].b = pVertices[4];	pFaces[7].c = pVertices[5];	pFaces[8].a = pVertices[1];	pFaces[8].b = pVertices[5];	pFaces[8].c = pVertices[2];	pFaces[9].a = pVertices[2];	pFaces[9].b = pVertices[5];	pFaces[9].c = pVertices[6];	pFaces[10].a = pVertices[2];	pFaces[10].b = pVertices[3];	pFaces[10].c = pVertices[6];	pFaces[11].a = pVertices[6];	pFaces[11].b = pVertices[3];	pFaces[11].c = pVertices[7];}mesh.h   struct vertex {	GLfloat x,y,z,r,g,b;};struct face {	vertex a,b,c;};class Mesh {public:	Mesh() : num_vertices(0),num_faces(0),render(true) {}	~Mesh() { 		if(pVertices)			delete [] pVertices;		if(pFaces)			delete [] pFaces;	}	virtual void draw();	void box(GLfloat size);private:	vertex* pVertices;	face* pFaces;	int num_vertices;	int num_faces;	bool bRender;};


Edit: took out color stuff that was not needed

[edited by - chbfiv on October 6, 2003 11:25:27 PM]
-BourkeIV
quote:Original post by chbfiv
I don''t really have an order to fillinf in my box, is that the problem?


Oh yes you do, the order in which you feed the vertices to triangles.
Change the vertex order per face to opposite to fix the culling.

Relevant code section:

void Mesh::draw() {  for(int i=0; i < num_faces; i++) {	glBegin(GL_TRIANGLES);		glVertex3f(pFaces[i].a.x,pFaces[i].a.y,pFaces[i].a.z);		glVertex3f(pFaces[i].b.x,pFaces[i].b.y,pFaces[i].b.z);		glVertex3f(pFaces[i].c.x,pFaces[i].c.y,pFaces[i].c.z);	glEnd();  }}


-Nik

Niko Suni

Man I''m losing it; Though none of my books explain what your talking about, nor did my google search help, I''m doing my best to understand.

If I''m drawing a simple cube, these are my steps.

1-fill in a vertex[8] struct''s xyz, using one value for size.
IE.
vertex[0].x = 0;vertex[0].y = 0;vertex[0].z = 0;vertex[1].x = cubesize;vertex[1].y = 0;vertex[1].z = 0;vertex[2].x = cubesize;vertex[2].y = 0;vertex[2].z = cubesize;vertex[3].x = 0;vertex[3].y = 0;vertex[3].z = cubesize;vertex[4].x = 0;vertex[4].y = cubesize;vertex[4].z = 0;vertex[5].x = cubesize;vertex[5].y = cubesize;vertex[5].z = 0;vertex[6].x = cubesize;vertex[6].y = cubesize;vertex[6].z = cubesize;vertex[7].x = 0;vertex[7].y = cubesize;vertex[7].z = cubesize;

a real simple positive space box.
2-fill in a face[12] struct''s abc(a=vertex,b=vertex,c=vertex)
pFaces[0].a = pVertices[0];pFaces[0].b = pVertices[1];pFaces[0].c = pVertices[2];pFaces[1].a = pVertices[0];pFaces[1].b = pVertices[2];pFaces[1].c = pVertices[3];pFaces[2].a = pVertices[4];pFaces[2].b = pVertices[5];pFaces[2].c = pVertices[6];pFaces[3].a = pVertices[4];pFaces[3].b = pVertices[6];pFaces[3].c = pVertices[7];pFaces[4].a = pVertices[0];pFaces[4].b = pVertices[3];pFaces[4].c = pVertices[4];pFaces[5].a = pVertices[3];pFaces[5].b = pVertices[7];pFaces[5].c = pVertices[4];pFaces[6].a = pVertices[0];pFaces[6].b = pVertices[4];pFaces[6].c = pVertices[1];pFaces[7].a = pVertices[1];pFaces[7].b = pVertices[4];pFaces[7].c = pVertices[5];pFaces[8].a = pVertices[1];pFaces[8].b = pVertices[5];pFaces[8].c = pVertices[2];pFaces[9].a = pVertices[2];pFaces[9].b = pVertices[5];pFaces[9].c = pVertices[6];pFaces[10].a = pVertices[2];pFaces[10].b = pVertices[3];pFaces[10].c = pVertices[6];pFaces[11].a = pVertices[6];pFaces[11].b = pVertices[3];pFaces[11].c = pVertices[7];

all the faces of the Box are connected, though with no order.
-now that you have everything in the face struct, thats all you need. Loop through each face, and render each triangle.
	glPushMatrix();		for(int i=0; i < num_faces; i++)	{		glBegin(GL_TRIANGLES);			glVertex3f(pFaces[i].a.x,pFaces[i].a.y,pFaces[i].a.z);			glVertex3f(pFaces[i].b.x,pFaces[i].b.y,pFaces[i].b.z);			glVertex3f(pFaces[i].c.x,pFaces[i].c.y,pFaces[i].c.z);			glEnd();	}	glPopMatrix();


I''ve done the following to try and fix my problem.
-glDisable(GL_CULL_FACE)
-glEnable(GL_CULL_FACE)
-glCullFace(GL_BACK)
-glCullFace(GL_FRONT)
-glCullFace(GL_FRONT_AND_BACK)

I don''t understand,
quote:
Oh yes you do, the order in which you feed the vertices to triangles.

Do you mean when I fill them into a face struct, or when I render them? And Why? Clockwise? I really dont understand that, this is a 3D space, that could be any direction in my eyes.

Just to explain what is happening one more time. I render the Box on the screen, but it seems that the face that should be behind the face closer to the sceen moves itself to the front.
It makes it look like the faces that are truly closer to the viewer seem clear so you can see in the Box.

Maybe i have a bad mindset about all this atm. It seems like a simple task.
-BourkeIV

This topic is closed to new replies.

Advertisement