简体   繁体   English

sdl osx eclipse c ++显示错误

[英]sdl osx eclipse c++ display error

I've got a problem in running SDL app in eclipse under osx. 我在osx下的Eclipse中运行SDL应用程序时遇到问题。

#include <SDL/SDL_opengl.h>
#include <SDL/SDL.h>
#include <SDL_ttf/SDL_ttf.h>
#include <SDL_image/SDL_image.h>
#include <iostream.h>

int main(int argc, char* argv[]){
    int error;
    error = SDL_Init(SDL_INIT_EVERYTHING);
    std::cout << "error " << error << std::endl;
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    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);

    Uint32 flags;

    flags = SDL_OPENGL | SDL_HWSURFACE | SDL_HWPALETTE| SDL_DOUBLEBUF ;
    drawContext = SDL_SetVideoMode(1024, 768, 16, flags);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0f, 1024, 768, 0.0f, 0.0f, 1000.0f);

    glMatrixMode(GL_MODELVIEW);

    while(true){
        glFinish();
        SDL_GL_SwapBuffers();
    }
}

this get weired output. 这得到奇怪的输出。 闪烁和分数

This only happens using the 仅在使用

SDL_OPENGL SDL_OPENGL

flag. 旗。

Any ideas? 有任何想法吗?

You never bother to clear the default framebuffer to a known value and the GL implementation isn't required to give you a cleared buffer. 您无需费心将默认帧缓冲区清除为已知值,并且不需要GL实现即可为您提供清除的缓冲区。

OpenGL 4.3 spec , page 254, paragraph 1 (emphasis mine): OpenGL 4.3规范 ,第254页,第1段(重点是我):

The default framebuffer is initially used as the draw and read framebuffer, and the initial state of all provided bitplanes is undefined . 默认情况下,默认帧缓冲区用作绘制帧和读取帧缓冲区,并且所有提供的位平面的初始状态都是undefined The format and encoding of buffers in the draw and read framebuffers can be queried as described in section 9.2.3. 绘制和读取帧缓冲区中缓冲区的格式和编码可以按照第9.2.3节中的说明进行查询。

Clear the framebuffer sometime before you swap: 在交换之前的某个时间清除帧缓冲区:

while(true)
{
    glClear( GL_COLOR_BUFFER_BIT );

    // draw stuff

    SDL_GL_SwapBuffers();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM