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 815501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:41:41+00:00 2026-05-15T01:41:41+00:00

I spent the last three days trying to create a small app using SDL

  • 0

I spent the last three days trying to create a small app using SDL + OpenGL. The app itself runs fine — except it never outputs any graphics; just a black screen.

I’ve condensed it down to a minimal C file, and I’m hoping someone can give me some guidance. I’m running out of ideas.

I’m using Windows Vista, MinGW & MSYS. Thanks in advance for any advice!

#include <SDL/SDL.h>
#include <SDL_opengl.h>

size_t sx=600, sy=600, bpp=32;

void render(void) {
    glEnable(GL_DEPTH_TEST);                                // enable depth testing

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                   // clear to black
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // clear color/depth buffer
    glLoadIdentity();                                       // reset modelview matrix

    glColor3b(255, 0, 0);                                   // red
    glLineWidth(3.0);                                       // line width=3
    glRecti(10, 10, sx-10, sy-10);                          // draw rectangle

    glFlush();
    SDL_GL_SwapBuffers();
}

int input(void) {
    SDL_Event event;
    while (SDL_PollEvent(&event))
        if (event.type == SDL_QUIT || (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE)) return 0;
    return 1;
}

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

    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) return 0;
    if (!(surf = SDL_SetVideoMode(sx, sy, bpp, SDL_HWSURFACE|SDL_DOUBLEBUF))) return 0;

    glViewport(0, 0, sx, sy);           // reset the viewport to new dimensions
    glMatrixMode(GL_PROJECTION);        // set projection matrix to be current
    glLoadIdentity();                   // reset projection matrix
    glOrtho(0, sx, sy, 0, -1.0, 1.0);   // create ortho view
    glMatrixMode(GL_MODELVIEW);         // set modelview matrix
    glLoadIdentity();                   // reset modelview matrix

    for (;;) {
        if (!input()) break;
        render();
        SDL_Delay(10);
    }

    SDL_FreeSurface(surf);
    SDL_Quit();
    exit(0);
}

UPDATE: I have a version that works, but it changes orthographic to perspective. I’m not sure why this works and the other doesn’t, but for future reference, here’s a version that works:

#include <SDL/SDL.h>
#include <SDL_opengl.h>

size_t sx=600, sy=600, bpp=32;

void render(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glLoadIdentity();                                       // set location in front of camera
    glTranslated(0, 0, -10);

    glBegin(GL_QUADS);                                      // draw a square
        glColor3d(1, 0, 0);
        glVertex3d(-2,  2,  0);
        glVertex3d( 2,  2,  0);
        glVertex3d( 2, -2,  0);
        glVertex3d(-2, -2,  0);
    glEnd();

    glFlush();
    SDL_GL_SwapBuffers();
}

int input(void) {
    SDL_Event event;
    while (SDL_PollEvent(&event))
        if (event.type == SDL_QUIT || (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE)) return 0;
    return 1;
}

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

    if (SDL_Init(SDL_INIT_EVERYTHING) != 0) return 0;
    if (!(surf = SDL_SetVideoMode(sx, sy, bpp, SDL_OPENGL))) return 0;

    glViewport(0, 0, sx, sy);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, (float)sx / (float)sy, 1.0, 100.0);
    glMatrixMode(GL_MODELVIEW);

    glClearColor(0, 0, 0, 1);
    glClearDepth(1.0);
    glEnable(GL_DEPTH_TEST);

    for (;;) {
        if (!input()) break;
        render();
        SDL_Delay(10);
    }

    SDL_FreeSurface(surf);
    SDL_Quit();
    return 0;
}
  • 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-05-15T01:41:42+00:00Added an answer on May 15, 2026 at 1:41 am

    In the first code block, change your glColor3b() call to glColor3ub(). Or pass in 127 instead of 255.

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

Sidebar

Related Questions

I spent the last three days working on the collection _ select form helper
I have spent last 3 days until I got gps working on android using
I've spent so much time the last few days trying to work out some
I've spent the last three hours trying to write a string to the console?
I'm new to Google App Engine, and I've spent the last few days building
I've spent the last few days putting together a game that runs as an
I've spent the last three hours trying to get a simple Twitter status update
I have spent the last couple of days trying to find the solution to
I'm sure this has been answered before, but I've spent the last three hours
i spent last few hours trying to find what is wrong in my code(?)

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.