Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenGL:没有绘制任何内容_C++_Opengl_Sdl_Codeblocks_Microsoft Glee - Fatal编程技术网

C++ OpenGL:没有绘制任何内容

C++ OpenGL:没有绘制任何内容,c++,opengl,sdl,codeblocks,microsoft-glee,C++,Opengl,Sdl,Codeblocks,Microsoft Glee,图形:AMD Radeon HD 7900系列 正在运行:Windows 7(64位) 程序:代码块(32位) OpenGL库:GLee 这是我设置窗口的地方。它是一个使用OpenGL渲染的SDL窗口 这是上面提到的SetGLState() 这是将图像绘制到屏幕的位置 这扇窗户什么也没画,我也不知道为什么。我已经有一段时间没有看这段代码了,但我知道在以前安装的windows上,它可以正常工作。我所有的其他项目都在运行,但这一个没有。它只是呈现一个空白屏幕。奇怪的是,我有一个调整窗口大小的功能。当

图形:AMD Radeon HD 7900系列

正在运行:Windows 7(64位)

程序:代码块(32位)

OpenGL库:GLee

这是我设置窗口的地方。它是一个使用OpenGL渲染的SDL窗口

这是上面提到的SetGLState()

这是将图像绘制到屏幕的位置

这扇窗户什么也没画,我也不知道为什么。我已经有一段时间没有看这段代码了,但我知道在以前安装的windows上,它可以正常工作。我所有的其他项目都在运行,但这一个没有。它只是呈现一个空白屏幕。奇怪的是,我有一个调整窗口大小的功能。当调用该函数时,屏幕将显示一个白色屏幕,而不是黑色屏幕

编辑** 一旦所有内容都被绘制到屏幕上,就会在最后调用此代码。它已经包含在我的代码中


SetGLState中设置的所有状态都是图形状态。从DrawImage函数调用它。最重要的是,glClear必须放在draw函数中,它在其他任何地方都没有意义

调用
glReadPixels
毫无意义


完成后必须交换缓冲区
SDL\u交换缓冲区
(IIRC,有一段时间没有使用SDL)。

我刚刚编辑了我的文章。你让我做的一切都已经完成了,只是在一个单独的函数中。我忘了包括在内。对不起,我的帖子现在应该没有其他代码丢失了。问题仍然存在。@user1959403:您应该将glClear not放在缓冲区交换调用之后。它看起来很奇怪,可能会混淆。通常,在开始画框架时,你总是很清楚。我仍然没有解决这个问题——即使在修正了你所有的建议之后。有什么与代码无关的问题吗?@user1959403:只看到你发布的代码片段,我没有主意了。我需要看完整的节目才能提出其他建议。我建议你把它放在pastebin.com或github网站上。
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();
}
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();
}
void Flip(){
    SDL_GL_SwapBuffers();
    glClear( GL_COLOR_BUFFER_BIT );
}