Sahil R.
asked 04/04/21what is the code
Write a Program in C/C++ with OpenGL using Glut.h to display your “First Name” using output primitives by defining vertices in 2d/3d.
1 Expert Answer
Rize S. answered 03/23/23
Senior IT Certified Trainer, IT Developer & DBA Administrator
Here's an example program in C++ with OpenGL using Glut.h library that displays a person's first name using output primitives by defining vertices in 2D:
#include <GL/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
glVertex2f(-0.5, 0.5); // Vertex A
glVertex2f(-0.5, -0.5); // Vertex B
glVertex2f(-0.25, -0.5); // Vertex C
glVertex2f(-0.25, 0.0); // Vertex D
glVertex2f(0.25, 0.0); // Vertex E
glVertex2f(0.25, -0.5); // Vertex F
glVertex2f(0.5, -0.5); // Vertex G
glVertex2f(0.5, 0.5); // Vertex H
glEnd();
glBegin(GL_POLYGON);
glVertex2f(-0.25, 0.0); // Vertex D
glVertex2f(-0.25, 0.25); // Vertex I
glVertex2f(0.25, 0.25); // Vertex J
glVertex2f(0.25, 0.0); // Vertex E
glEnd();
glFlush();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutCreateWindow("My Name");
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
This program defines the vertices of the letters of the name in 2D using glVertex2f() function and uses glBegin() and glEnd() functions to define the polygons for each letter. In this example, the letters "J" and "I" share a vertex to create a more compact shape. Finally, the glFlush() function is called to ensure that the changes to the frame buffer are actually displayed on the screen.
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Sahil R.
please tell the complete code with output , can be on c or c++ platform04/04/21