Saturday 7 December 2013

Filled Under:

Use the GL_TRIANGLES function:

GL_TRIANGLES function:

This primitive takes three vertices at a time and draws a triangle using them. If your application specifies n vertices, OpenGL renders n/3 triangles. If n isn't a multiple of 3, OpenGL ignores the excess vertices.

Example:

include header file
#include "stdafx.h"
#include<glut.h>
Defination of draw_trinagle function:
void Draw_triangle() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_TRIANGLES);
glVertex2f(0.20,0.95);
glVertex2f(0.15, 0.85);
glVertex2f(0.25,0.85);
glEnd();
glFlush();
}


int main(int iArgc, char** cppArgv) {
...
       ....
       /*basic initialization */
      ...
     ...
     ...
glutDisplayFunc(Draw_triangle);
glutMainLoop();
return 0;
}

output screen short:
 

Note:
        In /*basic initialization * area we create the window for drawing initialize the window and set the size of window u can see how to set and initialize the window click here
                                             




0 comments:

Post a Comment