显卡:AMD Radeon HD 7900 系列
运行:Windows 7(64 位)
程序:代码块(32 位)
OpenGL 库:GLee
这是我设置窗口的地方。它是一个使用 OpenGL 渲染的 SDL 窗口。
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();
}
这就是上面提到的 SetGLState()。
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);
}
这是将图像绘制到屏幕上的地方
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();
}
这个窗口没有绘制任何东西,我不知道为什么。我有一段时间没有看这段代码了,但我知道在以前安装的 Windows 中,我让它工作了。我所有的其他项目都在运行,但这个没有。它只是呈现一个空白屏幕。奇怪的是——我有这个窗口的调整大小功能。当调用该函数时,屏幕会显示白屏而不是黑屏。
编辑** 一旦所有内容都绘制到屏幕上,此代码将在最后调用。它已经包含在我的代码中。
void Flip(){
    SDL_GL_SwapBuffers();
    glClear( GL_COLOR_BUFFER_BIT );
}