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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:51:25+00:00 2026-05-27T13:51:25+00:00

I’m working on a program with OpenGL/SDL, but the window won’t draw. The window’s

  • 0

I’m working on a program with OpenGL/SDL, but the window won’t draw. The window’s entry appears in the taskbar and the alt+tab menu, but no thumbnail is shown. When I click it, it’s marked as active, but nothing changes onscreen.

I can verify that glClear(GL_COLOR_BUFFER_BIT) and SDL_GL_SwapBuffers() are being called from my render loop, and that SDL_SetVideoMode is succeeding, but it still won’t render. It’s not a shared library issue, since other SDL/GL apps work fine.

Any ideas?

EDIT:

Here’s the graphics initialization:

void GraphicsManager::initGraphics() {
    // Access prefs
    PreferencesManager* prefMgr = PreferencesManager::getInstance();
    int width = prefMgr->getIntKey("res_width");
    int height = prefMgr->getIntKey("res_height");

    if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
        fprintf(stderr, "Cannot initialize SDL video!\n");
        exit(1);
    }

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

    m_screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
    if(!m_screen) {
        fprintf(stderr, "Error: Invalid screen pointer\n");
        exit(2);
    }

    SDL_ShowCursor(SDL_DISABLE);

    // Setup OpenGL stuffs
    glDisable(GL_DEPTH_TEST); // We're only using 2D
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glViewport(0.0, 0.0, width, height);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, width, height, 0.0, -1.0f, 1.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glEnable(GL_TEXTURE_2D);
    glClear(GL_COLOR_BUFFER_BIT);
    SDL_GL_SwapBuffers();

    // Init FPS stuff
    m_avgFps = 60.0f;
    m_lastUpdate = SDL_GetTicks();
}

Here’s my main loop:

while(stateMgr->getState() != GS_QUIT) {
    // Process input events
    inputMgr->processEvents();

    // Update the current system mode
    stateMgr->update();

    // Update GUI state
    guiMgr->update();

    // Render
    gfxMgr->render();
    //char buf[16];
    //snprintf(buf, 16, "FPS: %4.2f", gfxMgr->getFramerate());
    //testWindow->getChild("TestRoot/Framerate")->setText(buf);
    SDL_Delay(10);
}

And here’s the render function:

void GraphicsManager::render() {
    std::list<IRenderCallback*>::iterator rci;

    // Clear the screen
    glClear(GL_COLOR_BUFFER_BIT);

    // Run render callbacks
    /*for(rci=m_renderCallbacks.begin();rci != m_renderCallbacks.end();rci++) {
        (*rci)->preRender();
    }

    // Iterate through all renderables and render them
    std::list<Renderable*>::iterator i;
    for(i=m_renderables.begin();i != m_renderables.end();i++) {
        (*i)->render();
    }

    // Run render callbacks
    for(rci=m_renderCallbacks.begin();rci != m_renderCallbacks.end();rci++) {
        (*rci)->preFlip();
    }*/

    // Flip the buffers
    SDL_GL_SwapBuffers();

    // Update FPS stuff
    Uint32 now = SDL_GetTicks();
    Uint32 timeTaken = now - m_lastUpdate;
    m_lastUpdate = now;
    double seconds = (double)timeTaken / 1000.0f;
    m_avgFps = (1.0f / seconds);

    // Run render callbacks
    for(rci=m_renderCallbacks.begin();rci != m_renderCallbacks.end();rci++) {
        (*rci)->postRender();
    }
}
  • 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-27T13:51:25+00:00Added an answer on May 27, 2026 at 1:51 pm

    Break it down. Do the (mostly-ish) simplest thing that should work:

    #include <SDL.h>
    #include <SDL_opengl.h>
    #include <cstdio>
    #include <iostream>
    
    using namespace std;
    
    int main( int argc, char** argv )
    {
        if(SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
            fprintf(stderr, "Cannot initialize SDL video!\n");
            exit(1);
        }
    
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
    
        int width = 640;
        int height = 480;
    
        SDL_Surface* m_screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
        if(!m_screen) {
            fprintf(stderr, "Error: Invalid screen pointer\n");
            exit(2);
        }
    
        cout << "GL_VERSION  : " << glGetString(GL_VERSION) << endl;
        cout << "GL_VENDOR   : " << glGetString(GL_VENDOR) << endl;
        cout << "GL_RENDERER : " << glGetString(GL_RENDERER) << endl;
    
        SDL_ShowCursor(SDL_DISABLE);
    
        // Setup OpenGL stuffs
        glDisable(GL_DEPTH_TEST); // We're only using 2D
        glClearColor(0.0, 0.0, 0.0, 0.0);
        glViewport(0.0, 0.0, width, height);
        glClear(GL_COLOR_BUFFER_BIT);
    
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0.0, width, height, 0.0, -1.0f, 1.0f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
        //glEnable(GL_TEXTURE_2D);
        glClear(GL_COLOR_BUFFER_BIT);
        SDL_GL_SwapBuffers();
    
        float angle = 0;
        bool running = true;
        while( running )
        {
            // handle all pending events
            SDL_Event event;
            while( SDL_PollEvent(&event) )
            {
                switch (event.type)
                {
                case SDL_QUIT:  
                    running = false; 
                    break;
                default:        
                    break;
                }
            }
    
            angle += 1;
            while( angle > 360 )
                angle -= 360;
    
            // Render
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
            glPushMatrix();
            glTranslatef( width/2, height/2, 0 );
            glScalef( 150, 150, 0 );
    
            glRotatef( angle, 0, 0, 1 );
            glColor3ub(255,0,0);
            glBegin(GL_TRIANGLES);
            glVertex2i(0,0);
            glVertex2i(1,0);
            glVertex2i(1,1);
            glEnd();
    
            glPopMatrix();
    
            // Flip the buffers
            SDL_GL_SwapBuffers();
    
            SDL_Delay(10);
        }
    
        SDL_Quit();
        return 0;
    }
    

    If that works all you have to do (ha!) is figure out how the simple program execution flow differs from your large program. If it doesn’t work your environment is probably goofed somehow.

    What do the GL_VERSION/VENDOR/RENDERER checks print on your system?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.