0
顯卡:的AMD Radeon HD 7900系列OpenGL的:沒有繪製
運行:的Windows 7(64位)
計劃:代碼塊(32位)
OpenGL庫: 歡樂
這是我的設置窗口。它是一個使用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);
}
我剛剛編輯我的帖子。你告訴我做的每件事都已經完成了,只是在一個單獨的功能中完成。我忘了包括它。現在我的帖子中應該沒有其他代碼丟失了,對不起。問題依然存在。 – bennybroseph
@ user1959403:你應該把glClear放在緩衝區交換調用之後。它看起來很奇怪,可能會混淆。你通常總是在畫框開始時清楚。 – datenwolf
我仍然沒有想出這個問題 - 即使在修正了所有建議之後。有沒有相關的代碼可能是問題? – bennybroseph