Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: polygon smoothing problem

  1. #1
    Newbie Newbie
    Join Date
    Apr 2014
    Posts
    1

    polygon smoothing problem

    my code is:
    Code :
    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:
    Attachment 1266

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

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    You are using GL_TRIANGLES so there vertices must be in multiples of 3. Do you mean to use GL_TRIANGLES_STRIP

  3. #3
    Intern Contributor
    Join Date
    Mar 2014
    Location
    San Jose, CA
    Posts
    58
    Quote Originally Posted by tonyo_au View Post
    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.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    I was having a bad day - no I could not open the attachment

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •