PDA

View Full Version : polygon smoothing problem



mahdi_12167
04-19-2014, 07:13 AM
my code is:


void display() {



glColor3f(1.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 1.2, 0, 0, 0, 0, 1, 0);
glRotatef(30,0,0,1);
glBegin(GL_TRIANGLES); // Start Drawing The Pyramid
glColor3f(0.0f, 1.0f, 0.0f); // Red

glVertex3f(-1.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
glVertex3f(-1.0f, -1.0f, 0.0f); // Left Of Triangle (Front)
glVertex3f(1.0f, -1.0f, 0.0f); // Right Of Triangle (Front)


glVertex3f(-1.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
glVertex3f(1.0f, -1.0f, 0.0f); // Left Of Triangle (Right)
glVertex3f(1.0f, 1.0f, 0.0f);
glEnd();
glFlush();
glutSwapBuffers();
}
void init(void)
{
/* Setup cube vertex data. */


/* Use depth buffering for hidden surface elimination. */
glDisable( GL_DEPTH_TEST ) ;
glClearColor( 1.0, 1.0, 1.0, 0.0 ) ; // white
glClear( GL_COLOR_BUFFER_BIT ) ;
float mulval = 0.01 ; // you might want to change this

glEnable( GL_BLEND ) ;
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; // works fine, except cracks
//glBlendFunc( GL_SRC_ALPHA_SATURATE, GL_ONE ) ; // works only on black background...
glPolygonMode( GL_FRONT, GL_FILL ) ;
glEnable( GL_POLYGON_SMOOTH ) ;
glHint( GL_POLYGON_SMOOTH_HINT, GL_NICEST ) ;
}
int main(int argc, char** argv) {

// Use a single buffered window in RGB mode (as opposed to a double-buffered
// window or color-index mode).
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB |GLUT_DEPTH | GLUT_STENCIL);

// Position window at (80,80)-(480,380) and give it a title.
glutInitWindowPosition(80, 80);
glutInitWindowSize(800, 600);
glutCreateWindow("A Simple Triangle");

// Tell GLUT that whenever the main window needs to be repainted that it
// should call the function display().
glutDisplayFunc(display);
glutReshapeFunc(reshape);
// Tell GLUT to start reading and processing events. This function
// never returns; the program only exits when the user closes the main
// window or kills the process.
init();
glutMainLoop();
return 0;
}


and result is:
1266

what is the line between of triangle? i want to remove it!!

tonyo_au
04-19-2014, 09:38 PM
You are using GL_TRIANGLES so there vertices must be in multiples of 3. Do you mean to use GL_TRIANGLES_STRIP

reto.koradi
04-19-2014, 11:00 PM
You are using GL_TRIANGLES so there vertices must be in multiples of 3.

I count 6 glVertex3f calls. Looks like a multiple of 3 to me.

Is the attachment working for anybody? It fails to open for me.

tonyo_au
04-20-2014, 07:03 PM
I was having a bad day - no I could not open the attachment