Close Menu
  • Home
  • Web Technologies
    • HTML/CSS
    • JavaScript
    • JQuery
    • Django
    • WordPress
  • Programming
    • Python
    • PHP
  • Linux
    • Ubuntu
Facebook X (Twitter) Instagram
  • About Us
  • Contact Us
  • Write for Us
  • AIO SEO TOLLS
Facebook X (Twitter) Instagram Pinterest VKontakte
mr.wixXsid
  • Home
  • Web Technologies
    • HTML/CSS
    • JavaScript
    • JQuery
    • Django
    • WordPress
  • Programming
    • Python
    • PHP
  • Linux
    • Ubuntu
mr.wixXsid
Home » OpenGL Shapes and Name
Uncategorized

OpenGL Shapes and Name

mrwixxsidBy mrwixxsidMay 12, 2026Updated:May 12, 2026No Comments6 Mins Read
Facebook Twitter Pinterest Tumblr Reddit WhatsApp Email
Share
Facebook Twitter LinkedIn Pinterest Email

2nd LAB

#include <GL/gl.h>
#include <GL/glut.h>

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);

    // =====================================
    // RECTANGLE
    // =====================================
    glColor3f(1.0f, 1.0f, 1.0f);

    glBegin(GL_QUADS);

        // Proper rectangle
        glVertex3f(0.08f, 0.08f, 0.0f);
        glVertex3f(0.38f, 0.08f, 0.0f);
        glVertex3f(0.38f, 0.32f, 0.0f);
        glVertex3f(0.08f, 0.32f, 0.0f);

    glEnd();

    // =====================================
    // HOUSE BODY
    // =====================================
    glColor3f(0.85f, 0.82f, 0.65f);

    glBegin(GL_QUADS);

        glVertex3f(0.52f, 0.08f, 0.0f);
        glVertex3f(0.82f, 0.08f, 0.0f);
        glVertex3f(0.82f, 0.35f, 0.0f);
        glVertex3f(0.52f, 0.35f, 0.0f);

    glEnd();

    // =====================================
    // ROOF
    // =====================================
    glColor3f(0.65f, 0.38f, 0.20f);

    glBegin(GL_TRIANGLES);

        glVertex3f(0.48f, 0.35f, 0.0f);
        glVertex3f(0.86f, 0.35f, 0.0f);
        glVertex3f(0.67f, 0.58f, 0.0f);

    glEnd();

    // =====================================
    // FLOATING TRIANGLE
    // =====================================
    glColor3f(0.3f, 0.8f, 0.4f);

    glBegin(GL_TRIANGLES);

        glVertex3f(0.15f, 0.60f, 0.0f);
        glVertex3f(0.35f, 0.60f, 0.0f);
        glVertex3f(0.25f, 0.82f, 0.0f);

    glEnd();

    glFlush();
}

void init(void)
{
    glClearColor(0.0, 0.0, 0.0, 0.0);

    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    glOrtho(0.0, 1.0, 0.0, 1.0, -10.0, 10.0);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

    glutInitWindowSize(600, 600);

    glutInitWindowPosition(100, 100);

    glutCreateWindow("Fixed Shapes");

    init();

    glutDisplayFunc(display);

    glutMainLoop();

    return 0;
}

Windows:

#include <windows.h>
#include <iostream>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

//Called when a key is pressed
void handleKeypress(unsigned char key, int x, int y) {
switch (key) {
case 27: //Escape key
exit(0);
}
}

//Initializes 3D rendering
void initRendering() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL); //Enable color
glClearColor(0.7f, 0.9f, 1.0f, 1.0f); //Change the background to sky blue
}

//Called when the window is resized
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}

float _angle = 30.0f;
float _cameraAngle = 0.0f;

//Draws the 3D scene
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-_cameraAngle, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, -5.0f);

glPushMatrix();
glTranslatef(0.0f, -1.0f, 0.0f);
glRotatef(_angle, 0.0f, 0.0f, -1.0f);

glBegin(GL_QUADS);

//Trapezoid
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.7f, -0.5f, 0.0f);
glVertex3f(0.7f, -0.5f, 0.0f);
glVertex3f(0.7f, 0.5f, 0.0f);
glVertex3f(-0.7f, 0.5f, 0.0f);

glEnd();

glPopMatrix();
glPushMatrix();
glTranslatef(1.0f, 1.0f, 0.0f);
glRotatef(_angle, 0.0f, 1.0f, 0.0f);
glScalef(0.7f, 0.7f, 0.7f);

glBegin(GL_TRIANGLES);
glColor3f(0.0f, 1.0f, 0.0f);

//Pentagon
glVertex3f(-0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(-0.5f, 0.0f, 0.0f);

glVertex3f(-0.5f, 0.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, 0.0f, 0.0f);

glVertex3f(-0.5f, 0.0f, 0.0f);
glVertex3f(0.5f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);


glEnd();

glPopMatrix();
glPushMatrix();
glTranslatef(-1.0f, 1.0f, 0.0f);
glRotatef(_angle, 1.0f, 0.0f, 0.0f);

glBegin(GL_TRIANGLES);

//Triangle
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.0f);

glEnd();

glPopMatrix();



glutSwapBuffers();
}

void update(int value) {
_angle += 2.0f;
if (_angle > 360) {
_angle -= 360;
}

glutPostRedisplay(); ////Tell GLUT that the scene has changed
glutTimerFunc(25, update, 0);
}

int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);

//Create the window
glutCreateWindow("Color");
initRendering();

//Set handler functions
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);

glutTimerFunc(25, update, 0); //Add a timer

glutMainLoop();
return 0;
}

3nd LAB LINUX

#include <windows.h>
#include <iostream>
#include <stdlib.h>

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

//Called when a key is pressed
void handleKeypress(unsigned char key, int x, int y) {
switch (key) {
case 27: //Escape key
exit(0);
}
}

//Initializes 3D rendering
void initRendering() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL); //Enable color
glClearColor(0.7f, 0.9f, 1.0f, 1.0f); //Change the background to sky blue
}

//Called when the window is resized
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}

float _angle = 30.0f;
float _cameraAngle = 0.0f;

//Draws the 3D scene
void drawScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-_cameraAngle, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, -5.0f);

glPushMatrix();
glTranslatef(0.0f, -1.0f, 0.0f);
glRotatef(_angle, 0.0f, 0.0f, -1.0f);

glBegin(GL_QUADS);

//Trapezoid
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(-0.7f, -0.5f, 0.0f);
glVertex3f(0.7f, -0.5f, 0.0f);
glVertex3f(0.7f, 0.5f, 0.0f);
glVertex3f(-0.7f, 0.5f, 0.0f);

glEnd();

glPopMatrix();
glPushMatrix();
glTranslatef(1.0f, 1.0f, 0.0f);
glRotatef(_angle, 0.0f, 1.0f, 0.0f);
glScalef(0.7f, 0.7f, 0.7f);

glBegin(GL_TRIANGLES);
glColor3f(0.0f, 1.0f, 0.0f);

//Pentagon
glVertex3f(-0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(-0.5f, 0.0f, 0.0f);

glVertex3f(-0.5f, 0.0f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, 0.0f, 0.0f);

glVertex3f(-0.5f, 0.0f, 0.0f);
glVertex3f(0.5f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);


glEnd();

glPopMatrix();
glPushMatrix();
glTranslatef(-1.0f, 1.0f, 0.0f);
glRotatef(_angle, 1.0f, 0.0f, 0.0f);

glBegin(GL_TRIANGLES);

//Triangle
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);
glVertex3f(-0.5f, -0.5f, 0.0f);

glEnd();

glPopMatrix();



glutSwapBuffers();
}

void update(int value) {
_angle += 2.0f;
if (_angle > 360) {
_angle -= 360;
}

glutPostRedisplay(); ////Tell GLUT that the scene has changed
glutTimerFunc(25, update, 0);
}

int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);

//Create the window
glutCreateWindow("Color");
initRendering();

//Set handler functions
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);

glutTimerFunc(25, update, 0); //Add a timer

glutMainLoop();
return 0;
}

Printing Name: (IMRAN)

#include <GL/glut.h>

// Function to draw letters
void drawName() {
    glLineWidth(3);

    glBegin(GL_LINES);

    // I
    glVertex2f(-0.9, 0.5);
    glVertex2f(-0.9, -0.5);

    // M
    glVertex2f(-0.7, -0.5);
    glVertex2f(-0.7, 0.5);

    glVertex2f(-0.7, 0.5);
    glVertex2f(-0.6, 0.0);

    glVertex2f(-0.6, 0.0);
    glVertex2f(-0.5, 0.5);

    glVertex2f(-0.5, 0.5);
    glVertex2f(-0.5, -0.5);

    // R
    glVertex2f(-0.3, -0.5);
    glVertex2f(-0.3, 0.5);

    glVertex2f(-0.3, 0.5);
    glVertex2f(-0.1, 0.5);

    glVertex2f(-0.1, 0.5);
    glVertex2f(-0.1, 0.0);

    glVertex2f(-0.1, 0.0);
    glVertex2f(-0.3, 0.0);

    glVertex2f(-0.3, 0.0);
    glVertex2f(-0.1, -0.5);

    // A
    glVertex2f(0.1, -0.5);
    glVertex2f(0.2, 0.5);

    glVertex2f(0.2, 0.5);
    glVertex2f(0.3, -0.5);

    glVertex2f(0.15, 0.0);
    glVertex2f(0.25, 0.0);

    // N
    glVertex2f(0.5, -0.5);
    glVertex2f(0.5, 0.5);

    glVertex2f(0.5, 0.5);
    glVertex2f(0.7, -0.5);

    glVertex2f(0.7, -0.5);
    glVertex2f(0.7, 0.5);

    glEnd();
}

// Display function
void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 1.0, 1.0); // White color

    drawName();

    glFlush();
}

// Initialization
void init() {
    glClearColor(0.0, 0.0, 0.0, 1.0); // Black background
    gluOrtho2D(-1, 1, -1, 1);
}

// Main function
int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitWindowSize(800, 500);
    glutCreateWindow("Draw Name using OpenGL");

    init();
    glutDisplayFunc(display);
    glutMainLoop();

    return 0;
}

Print IMRAN with Line

#include <GL/glut.h>

// Helper to draw a single line
void line(float x1, float y1, float x2, float y2) {
    glVertex2f(x1, y1);
    glVertex2f(x2, y2);
}

void drawName() {
    glLineWidth(3);
    glBegin(GL_LINES);

    // I
    line(-0.9, 0.5, -0.9, -0.5);

    // M
    line(-0.7, -0.5, -0.7, 0.5);
    line(-0.7, 0.5, -0.6, 0.0);
    line(-0.6, 0.0, -0.5, 0.5);
    line(-0.5, 0.5, -0.5, -0.5);

    // R
    line(-0.3, -0.5, -0.3, 0.5);
    line(-0.3, 0.5, -0.1, 0.5);
    line(-0.1, 0.5, -0.1, 0.0);
    line(-0.1, 0.0, -0.3, 0.0);
    line(-0.3, 0.0, -0.1, -0.5);

    // A
    line(0.1, -0.5, 0.2, 0.5);
    line(0.2, 0.5, 0.3, -0.5);
    line(0.15, 0.0, 0.25, 0.0);

    // N
    line(0.5, -0.5, 0.5, 0.5);
    line(0.5, 0.5, 0.7, -0.5);
    line(0.7, -0.5, 0.7, 0.5);

    glEnd();
}

void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0, 0, 0); 
    drawName();
    glFlush();
}

void init() {
    glClearColor(1, 1, 1, 1); 
    gluOrtho2D(-1, 1, -1, 1);
}

int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitWindowSize(800, 500);
    glutCreateWindow("IMRAN");

    init();
    glutDisplayFunc(display);
    glutMainLoop();
}
Share. Facebook Twitter Pinterest Tumblr Reddit Telegram WhatsApp Email
mrwixxsid
  • Website
  • Facebook
  • X (Twitter)
  • Instagram

I am a Full-Stack Web Developer & Security Analyst from Bangladesh. I have built web/online applications on various Open Source Stacks and love information security testing.

Related Posts

Even Odd number’s in Assembly

April 10, 2025
Add A Comment
Leave A Reply Cancel Reply

Latest Articles

OpenGL Shapes and Name

May 12, 2026

Linux Privilege Escalation and Persistence

February 9, 2026

Create B2B Pricing with User Roles in WooCommerce

January 26, 2026

How to Wirelessly Update ESP32 Firmware with OTA

June 12, 2025

Even Odd number’s in Assembly

April 10, 2025
About

Mr.wixXsid is a website that publishes Web technologies, Programming, Linux, and Open-source ERP articles for an aspirant like you and us. We are in-depth research & present valuable content & resources to help the Web professional of all levels.

Latest

OpenGL Shapes and Name

May 12, 2026

Linux Privilege Escalation and Persistence

February 9, 2026
Other sites
  • BLOG
  • SEO TOOL’S
  • All in One Video Downloader
  • SELFISH WORLD
Copyright © 2026 mr.wixXsid. All rights reserved.
  • Privacy Policy
  • Terms of Use
  • Advertise

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.