Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8286541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:48:17+00:00 2026-06-08T11:48:17+00:00

#include <GL/gl.h> #include <GL/glut.h> void display(); void init(); int main(int argc, char* argv[]) {

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

void display();
void init();

int main(int argc, char* argv[])
{
    init();

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(320, 240);
    glutCreateWindow("Main Window");
    glutDisplayFunc(display);
    glutMainLoop();

    return 0;
}

void init()
{
    glDisable(GL_DEPTH_TEST);
}

void display()
{
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();

    glBegin(GL_QUADS);
    glColor3i(255,255,255);
        glVertex2f(10, 10);
        glVertex2f(100, 10);
        glVertex2f(100, 100);
        glVertex2f(10, 100);
    glEnd();

    glutSwapBuffers();
}

Theoretically, this code should draw a white rectangle. But all I see is a black empty screen. What’s wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:48:19+00:00Added an answer on June 8, 2026 at 11:48 am

    Here is my working example with the changes I made noted by comments:

    #include <gl/glut.h>
    #include <gl/gl.h>
    
    #define WINDOW_WIDTH 320
    #define WINDOW_HEIGHT 240
    
    void display();
    void init();
    
    int main(int argc, char* argv[])
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
        glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
        glutCreateWindow("Main Window");
        init(); // changed the init function to come directly before display function
        glutDisplayFunc(display);
        glutMainLoop();
    
        return 0;
    }
    
    void init()
    {
        glClearColor(0, 0, 0, 0); // moved this line to be in the init function
        glDisable(GL_DEPTH_TEST);
    
        // next four lines are new
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0, WINDOW_WIDTH-1, WINDOW_HEIGHT-1, 0, -1.0, 1.0);
        glMatrixMode(GL_MODELVIEW);
    }
    
    void display()
    {
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
    
        glBegin(GL_QUADS);
        glColor3ub(255,255,255); // changed glColor3i to glColor3ub (see below)
            glVertex2f(10, 10);
            glVertex2f(100, 10);
            glVertex2f(100, 100);
            glVertex2f(10, 100);
        glEnd();
    
        glFlush(); // added this line 
        //glutSwapBuffers(); // removed this line
    }
    

    glColor3ub is the function you want to use if you want to provide colors in the 0-255 range.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdio.h> #include <GL/gl.h> #include <GL/glut.h> #define KEY_ESCAPE 27 void display(); void keyboard(unsigned char,int,int);
I have simplified my problem to this example: #include <GL/glut.h> int main(int argc, char**
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =
#include <stdio.h> void main() { int x=5,y=6; printf(%d%d%d,x++,(y=x++),(x=y++)); } Can anyone please explain why
#include <iostream> #include <tuple> int main(){ auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1 auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>()); //Line 2
#include <iostream> using namespace std; int main() { int a, b, c, max; cout<<a=;
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
#include <iostream> #include <string> using namespace std; string crash() { } int noCrash() {
I have the following the class: //Rectangle.h #include Point.h class Rectangle{ public: Rectangle(); void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.