2008-10-16 6 views
0

Je viens de commencer avec opengl mais j'ai rencontré un comportement étrange. Ci-dessous j'ai posté du code qui fonctionne bien en xp mais sur Vista il rend juste l'écran noir.problème opengl sous Vista

Désolé d'avoir affiché un code long inhabituel (comme pour cette carte).

Y a-t-il quelque chose de très spécifique à ouvrir gl in vista? Merci.

#include<windows.h> 
#include<gl\gl.h> 
#include<gl\glu.h> 
#pragma comment(lib, "opengl32.lib") 
#pragma comment(lib, "glu32.lib") 

void InitGL(void) 
{ 
glClearColor(1,0.3f,0.3f,0.3f); 
} 

void DrawGLScene(void) 
{ 
/* code removed */ 
} 

HGLRC hRC = NULL; 
HDC hDC = NULL; 
HWND hWnd = NULL; 
HINSTANCE hInstance = NULL; 
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); 

bool CreateGLWindow(char* title, int width, int height) 
{ 
GLuint PixelFormat; 
WNDCLASS wc; 
RECT WindowRect; 
WindowRect.left = (long)0; 
WindowRect.right = (long)width; 
WindowRect.top = (long)0; 
WindowRect.bottom = (long)height; 
LPCSTR nazwa = TEXT("Start"); 

hInstance = GetModuleHandle(NULL); 
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; 
wc.lpfnWndProc = (WNDPROC)WndProc; 
wc.cbClsExtra = 0; 
wc.cbWndExtra = 0; 
wc.hInstance = hInstance; 
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); 
wc.hCursor = LoadCursor(NULL, IDC_ARROW); 
wc.hbrBackground = NULL; 
wc.lpszMenuName = NULL; 
wc.lpszClassName = nazwa; 

RegisterClass(&wc); 

hWnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, nazwa, 
         nazwa, 
         WS_SYSMENU | 
         WS_CLIPSIBLINGS | 
         WS_CLIPCHILDREN, 
         0,0, 
         width, 
         height, 
         NULL, 
         NULL, 
         hInstance, 
         NULL); 

static PIXELFORMATDESCRIPTOR pfd = 
{ 
    sizeof(PIXELFORMATDESCRIPTOR), 
    1, 
    PFD_DRAW_TO_WINDOW | 
    PFD_SUPPORT_OPENGL | 
    PFD_DOUBLEBUFFER, 
    PFD_TYPE_RGBA, 
    32, 
    0,0,0,0,0,0, 
    0, 
    0, 
    0, 
    0,0,0,0, 
    16, 
    0, 
    0, 
    PFD_MAIN_PLANE, 
    0, 
    0,0,0 
}; 

hDC = GetDC(hWnd); 
PixelFormat = ChoosePixelFormat(hDC, &pfd); 
HRESULT rez = SetPixelFormat(hDC, PixelFormat, &pfd); 
hRC = wglCreateContext(hDC); 
wglMakeCurrent(hDC, hRC); 
ShowWindow(hWnd, SW_SHOW); 
InitGL(); 
return true; 

} 

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
{ 
switch(uMsg) 
{ 
case WM_ACTIVATE: 
    { 
     return 0; 
    } 
case WM_CLOSE: 
    { 
     PostQuitMessage(0); 
     return 0; 
    } 
} 

return DefWindowProc(hWnd, uMsg, wParam, lParam); 
} 

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, 
int nCmdShow) 
{ 
MSG msg; 
bool done = false; 

if (!CreateGLWindow(NULL, 800,600)) 
{ 
    return 0; 
} 

while(!done) 
{ 
    if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) 
    { 
     if (!GetMessage(&msg, 0, 0, 0)) done = true; 
     else { 
      TranslateMessage(&msg); 
      DispatchMessage(&msg); 
     } 
    } 
    else 
    { 
     DrawGLScene(); 
     SwapBuffers(hDC); 
    } 
} 

return (msg.wParam); 
} 

Répondre

1

Qu'est-ce que c'est censé faire? Selon le code que vous avez posté là, il ne devrait rien faire sauf afficher un écran noir. Qu'attendez-vous qu'il se passe? La seule chose que je vois est que vous définissez glClearColor, mais vous n'appelez jamais glClear pour ne rien faire.

+0

Désolé, c'était mon erreur. Merci de l'avoir signalé. – kamilw

+0

@kamilo: Alors comment cela a-t-il bien fonctionné sur XP? –

+0

Réécriture sur Vista J'ai raté celui-ci. Je dois mettre des espaces entre les lignes pour ne pas omettre quelque chose d'important la prochaine fois. – kamilw

0

Essayez PFD_SUPPORT_COMPOSITION.

Si cela échoue, veuillez publier le résultat de DescribePixelFormat et glGetString(GL_RENDERER); pour aider à diagnostiquer un peu plus le problème.

+0

C'était mon erreur, comme souligné par Gerald. Merci pour votre réponse de toute façon. – kamilw