gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
hey, i'm new in opengl, help me with example code
- User
hey, i'm new in opengl, help me with example code
- Assistant
Sure! Here's a simple example code in C++ using OpenGL to create a basic 2D triangle:
cpp#include <GL/glut.h> // Include the GLUT library void display() { glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer glBegin(GL_TRIANGLES); // Begin drawing triangles glColor3f(1.0, 0.0, 0.0); // Set color to red glVertex2f(-0.6, -0.4); // Vertex 1 glColor3f(0.0, 1.0, 0.0); // Set color to green glVertex2f(0.6, -0.4); // Vertex 2 glColor3f(0.0, 0.0, 1.0); // Set color to blue glVertex2f(0.0, 0.6); // Vertex 3 glEnd(); // End drawing triangles glFlush(); // Flush OpenGL pipeline } int main(int argc, char** argv) { glutInit(&argc, argv); // Initialize GLUT glutCreateWindow("OpenGL Example"); // Create a window with a title glutDisplayFunc(display); // Set the display callback function glutMainLoop(); // Enter the GLUT event processing loop return 0; }