Results 1 to 5 of 5

Thread: Culling on even if I didn't turn it on?

  1. #1
    Member Newbie
    Join Date
    Jun 2000
    Location
    Ulricehamn, Sweden
    Posts
    49

    Culling on even if I didn't turn it on?

    I'm new to OpenGL. As a matter of fact this is the first program I attempted. It's supposed to be a spinning cube. And a cube it is. If I set glPolygonMode(GL_FRONT_AND_BACK,GL_LINE) it looks very much like I want it to look. The problems begin when I use polygon mode GL_POLYGON.
    You see, it appears as if back-faces are culled, even though I haven't turned culling on. I even tried using glDisable() to turn it off in case it was on by default, but that didn't do much.
    It sorta looks like the polygons are semitransparent too. That's weird. I haven't gotten to the blending part of my OpenGL book so I don't know how to turn off blending (if it is on by default for some reason).

    It's very weird and I can't for the life of me figure out what the problem is.

    Here's the code. It's fairly simple and straight-forward.

    Code :
    #include <GL\glut.h>
     
    GLfloat xRotated, yRotated, zRotated;
    GLfloat cubeverts[] = {
    	-1.0,-1.0,-1.0,	  //vertex no 1
    	-1.0,1.0,-1.0,				//2
    	-1.0,1.0,1.0,				//3
    	-1.0,-1.0,1.0,				//4
    	1.0,-1.0,1.0,				//5
    	1.0,-1.0,-1.0,				//6
    	1.0,1.0,1.0,				//7
    	1.0,1.0,-1.0				//8
    };
     
    GLfloat cubecolors[] = {  //colors corresponding to vertices
    	0.5,0.2,0.8,1.0,
    	0.8,0.1,0.7,1.0,
    	0.1,0.9,0.6,1.0,
    	0.4,0.8,0.6,1.0,
    	0.1,0.7,0.8,1.0,
    	0.8,0.6,0.4,1.0,
    	0.9,0.5,0.2,1.0,
    	0.2,0.5,0.6,1.0
     
    };
     
    unsigned char cubeindeces[] = {  //indeces in the vertex array to draw the cube
    	0,3,2,1,	  //4 indeces per polygon. We use GL_QUADS
    	2,3,4,6,
    	0,5,4,3,	  //All are numbered CCW as seen from the outside
    	1,2,6,7,
    	7,6,4,5,
    	1,7,5,0
    };
     
    void Display(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT);
    	glLoadIdentity();
    	glTranslatef(0.0,0.0,-10.5);
     
    	glRotatef(xRotated,1.0,0.0,0.0);
    	glRotatef(yRotated,0.0,1.0,0.0);
    	glRotatef(zRotated,0.0,0.0,1.0);
     
     
    	glDrawElements(GL_QUADS,24,GL_UNSIGNED_BYTE,cubeindeces);
     
     
    	glFlush();			//Finish rendering
    	glutSwapBuffers();
    }
     
    void Reshape(int w, int h)
    {
    	if (h == 0 | | w == 0) return;  //Nothing is visible then, so return
    	//Set a new projection matrix
    	glMatrixMode(GL_PROJECTION);  
    	glLoadIdentity();
    	//Angle of view:30 degrees
    	//Near clipping plane distance: 0.5
    	//Far clipping plane distance: 20.0
    	gluPerspective(30.0,(GLdouble)w/(GLdouble)h,0.0,20.0);
    	glMatrixMode(GL_MODELVIEW);
    	glViewport(0,0,w,h);  //Use the whole window for rendering
    }
     
    void Idle(void)
    {
    	xRotated += 0.093;
    	yRotated += 0.061;
    	zRotated += -.08;
    	glutPostRedisplay();
    }
     
     
    int main (int argc, char **argv)
    {
    	//Initialize GLUT
    	glutInit(&amp;argc, argv);
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);  //For animations you should use double buffering
    	glutInitWindowSize(320,200);
    	//Create a window with rendering context and everything else we need
    	glutCreateWindow("Mitt första OGL progg");
    	glPolygonMode(GL_FRONT_AND_BACK,GL_POLYGON);
    	xRotated = yRotated = zRotated = 0.0;
    	glClearColor(0.0,0.0,0.0,0.0);
    	//Assign the three used Msg-routines
    	glutDisplayFunc(Display);
    	glutReshapeFunc(Reshape);
    	glutIdleFunc(Idle);
    	//Let GLUT get the msgs
     
     
    	//Load vertex arrays and color arrays with cube data
    	//for super-fast rendering
    	glEnableClientState(GL_VERTEX_ARRAY);
    	glEnableClientState(GL_COLOR_ARRAY);
     
    	glVertexPointer(	3,			//x,y,z-coordinates
    						GL_FLOAT,	//data type is float
    						0,			//No stride
    						cubeverts);	
    	glColorPointer(		4,			//RGBA components
    						GL_FLOAT,	//data type is float
    						0,			//No stride
    						cubecolors);
    	//Start GLUT-loop
     
    	glDisable(GL_CULL_FACE);
     
    	glutMainLoop();
    	return 0;
    }

    If you can help me I would be really grateful! Thank you in advance.

    [This message has been edited by Caesar (edited 06-21-2000).]

  2. #2
    Member Contributor
    Join Date
    Feb 2000
    Location
    Stafford, UK
    Posts
    60

    Re: Culling on even if I didn't turn it on?

    GL_POLYGON draws a solid (filled) polygon as GL_LINE draws the outline of a polygon, so by specifying GL_POLYGON it will draw a solid shape.

    Also note that when you call gldrawelements(...) you use GL_QUADS which are also filled, you can change this to GL_LINES but it does draw the cube strangely...

  3. #3
    Member Newbie
    Join Date
    Jun 2000
    Location
    Ulricehamn, Sweden
    Posts
    49

    Re: Culling on even if I didn't turn it on?

    Where am I supposed to specify GL_POLYGON?

    here: glPolygonMode(GL_FRONT_AND_BACK,GL_POLYGON);

    I've already done that. It still doesn't work. If I specify GL_LINES I can see that it is indeed a perfect cube, but I can't get it to render properly when I use filled polygons to render it.

    I also tried enabling depth-test (with depth clear of 1.0f) using the depthfunc GL_LEQUAL. That resulted in massive flickering of the polys.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jun 2000
    Location
    Shreveport, LA, USA
    Posts
    1,502

    Re: Culling on even if I didn't turn it on?

    I notice you have the near plane set to 0. I've read in many places that you should not set it to zero. I'd try setting it to 1 or so.

  5. #5
    Member Newbie
    Join Date
    Jun 2000
    Location
    Ulricehamn, Sweden
    Posts
    49

    Re: Culling on even if I didn't turn it on?

    Thanks! That's it! It works perfectly now!

Similar Threads

  1. GL didn't work in OSX, but in Windows
    By hesheit in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 10-08-2013, 09:30 AM
  2. glgeneratemipmap()didn't run correctly
    By ashi08104 in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 03-10-2011, 05:47 PM
  3. Trying to do text input for OpenGL but didn't know the code
    By PhoenixByte in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-20-2005, 03:16 AM
  4. Wow, I didn't know this would come out like it did...
    By grady in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-23-2001, 12:34 PM
  5. I didn't even get started!
    By Ghitza in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-20-2001, 12:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean