0% found this document useful (0 votes)
10 views1 page

OpenGL Triangle Rendering Example

The document contains a C++ program that uses the FreeGLUT library to create a simple window displaying a colored triangle. The triangle is rendered with red, green, and blue vertices. The program initializes the GLUT environment, sets up the display mode, and enters the main event loop.

Uploaded by

naresh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

OpenGL Triangle Rendering Example

The document contains a C++ program that uses the FreeGLUT library to create a simple window displaying a colored triangle. The triangle is rendered with red, green, and blue vertices. The program initializes the GLUT environment, sets up the display mode, and enters the main event loop.

Uploaded by

naresh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

#include <GL/freeglut.

h>

void display() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(0.0f, 0.5f);
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex2f(-0.5f, -0.5f);
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex2f(0.5f, -0.5f);
glEnd();
glFlush();
}

int main(int argc, char** argv) {


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("Hello Triangle");
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

You might also like