0

Graphics: AMD Radeon HD 7900 Series

Running: Windows 7(64 bit)

Program: CodeBlocks(32 bit)

OpenGL Library: GLee

This is where I setup the window. Its an SDL window using OpenGL rendering.

void Init(int w, int h, bool fullScr)
{
    if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
    printf("Unable to initialize SDL: %s\n", SDL_GetError());
    }
    winW = w*scale;
    winH = h*scale;
    original_winW = w;
    origianl_winH = h;

    putenv("SDL_VIDEO_WINDOW_POS");
    putenv("SDL_VIDEO_CENTERED=1");

    getenv("SDL_VIDEO_WINDOW_POS");
    getenv("SDL_VIDEO_CENTERED");

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*
    SDL_GL_SetAttribute( SDL_GL_SWAP_CONTROL, 0 ); // *new*

    //Sets up the screen and displays the window
    screen = SDL_SetVideoMode( winW, winH, 32, SDL_OPENGL | (fullScr*SDL_FULLSCREEN)  ); // *changed*
    screenRect.x = 0;
    screenRect.y = 0;
    screenRect.w = winW;
    screenRect.h = winH;

    SDL_ShowCursor(false);

    SetGLState();
}

This is the SetGLState() mentioned above.

void SetGLState(){
    glEnable( GL_TEXTURE_2D ); //Enable 2d texturing

    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); //Set clear color (rgba)

    glViewport( 0, 0, winW, winH ); //Set the viewport

    glClear( GL_COLOR_BUFFER_BIT ); //Clear back buffer?

    glMatrixMode( GL_PROJECTION ); //Set to projection
    glLoadIdentity();

    glOrtho(0.0f, winW, winH, 0.0f, -1.0f, 1.0f); //Create orthogonal projection matrix

    glMatrixMode( GL_MODELVIEW ); //Set back to model view
    glLoadIdentity();

    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

This is where the images are drawn to the screen

void DrawImage(GLSurface image, float x, float y)
{
    // Bind the texture to which subsequent calls refer to
    if(boundTexture != image.Surface){glBindTexture( GL_TEXTURE_2D, image.Surface ); boundTexture = image.Surface; }

    glReadPixels(x,y,image.w*2,image.h*2,GL_UNSIGNED_BYTE,NULL,NULL);

    glLoadIdentity();
    glScalef(scale,scale,1);

    glRotatef(image.rotation[0], 1.0f, 0.0f, 0.0f);
    glRotatef(image.rotation[1], 0.0f, 1.0f, 0.0f);
    glRotatef(image.rotation[2], 0.0f, 0.0f, 1.0f);

    if(scale == 7.5)x += 48;

    glBegin( GL_QUADS );
        //Bottom-left vertex (corner)
        glColor3b(127,127,127);
        glTexCoord2i( 0, 0 ); //Position on texture to begin interpolation
        glVertex3f( x, y, 0.f ); //Vertex Coords

        //Bottom-right vertex (corner)
        glTexCoord2i( 1, 0 );
        glVertex3f( x+image.w, y, 0.f );

        //Top-right vertex (corner)
        glTexCoord2i( 1, 1 );
        glVertex3f( x+image.w, y+image.h, 0.f );

        //Top-left vertex (corner)
        glTexCoord2i( 0, 1 );
        glVertex3f( x, y+image.h, 0.f );
    glEnd();
}

This window doesn't draw anything, and I can't figure out why. I haven't looked at this code in awhile, but I know that on a previous install of windows, I had it working. All of my other projects run, but this one doesn't. It just renders a blank screen. The weird thing is--I have a resize function for this window. When that function gets called, the screen displays a white screen instead of a black one.

Edit** This code is called at the end once everything has been drawn to the screen. It was already included in my code.

void Flip(){
    SDL_GL_SwapBuffers();
    glClear( GL_COLOR_BUFFER_BIT );
}

1 Answers1

1

All the state set in SetGLState is drawing state. Call it from the DrawImage function. Most importantly, glClear must be put in the draw function, it doesn't make sense anywhere else.

That call to glReadPixels makes no sense.

And you must swap the buffers when done SDL_SwapBuffers (IIRC, haven't used SDL in some time).

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • I just edited my post. Everything you told me to do was already done, just in a separate function. I forgot to include it. There should be no other code missing from my post now, sorry. The problem still remains. – bennybroseph Jan 10 '13 at 10:48
  • 1
    @user1959403: You should put glClear not after the buffer swap call. It looks weird and may confuse. You normally always clear at the begin of drawing a frame. – datenwolf Jan 10 '13 at 12:09
  • I still haven't figured this problem out--even after fixing all of your suggestions. Is there something not code related that could be the problem? – bennybroseph Jan 15 '13 at 01:12
  • @user1959403: Seeing only the code snippets you posted I'm out of ideas. I need to see the full program to make any other suggestions. I suggest you put it on pastebin.com or into a github gist. – datenwolf Jan 15 '13 at 01:48