elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Los 10 CVE más críticos (peligrosos) de 2020


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  (Ayuda con OpenGL) La función 'SetPixelFormat' me da un error
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: (Ayuda con OpenGL) La función 'SetPixelFormat' me da un error  (Leído 1,510 veces)
Seyro97

Desconectado Desconectado

Mensajes: 145


Ver Perfil WWW
(Ayuda con OpenGL) La función 'SetPixelFormat' me da un error
« en: 8 Junio 2015, 05:05 am »

Hola, muy buenas a tod@s, os comento:

Estaba creando un simple Hello World de OpenGL usando la API de Windows. He ido paso a paso, creando primero una ventana simple con la API de Windows (la cual se ha creado correctamente), y posteriormente he creado un contexto con el viejo OpenGL. El problema lo da la función SetPixelFormat, el cual da el código de error 3221684230 (en hexadecimal 0xC0070006). No tengo ni idea de que puede pasar, incluso he copiado/pegado un código de un contexto de OpenGL de Internet y me pasa lo mismo...

Código
  1. #ifndef UNICODE
  2. #define UNICODE
  3. #endif
  4.  
  5. #include <windows.h>
  6. #include <gl\gl.h>
  7.  
  8. #include <chrono>
  9. #include <thread>
  10.  
  11. #include <iostream>
  12.  
  13. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  14.  
  15. int main() {
  16. WNDCLASSEX cWindow;
  17. HWND hWnd;
  18. MSG Msg;
  19. HDC hDC;
  20. HGLRC hRC;
  21.  
  22. memset(&Msg, NULL, sizeof(MSG));
  23.  
  24. cWindow.cbSize = sizeof(WNDCLASSEX);
  25. cWindow.hInstance = GetModuleHandle(NULL);
  26. cWindow.lpszClassName = L"¡Título!";
  27. cWindow.lpfnWndProc = WndProc;
  28. cWindow.lpszMenuName = NULL;
  29. cWindow.style = CS_OWNDC;
  30. cWindow.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  31. cWindow.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  32. cWindow.hCursor = LoadCursor(NULL, IDC_ARROW);
  33. cWindow.hbrBackground = (HBRUSH)3;
  34. cWindow.cbClsExtra = 0;
  35. cWindow.cbWndExtra = 0;
  36.  
  37. if(RegisterClassEx(&cWindow) == NULL) {
  38. MessageBox(NULL, L"Error registring a window class!", L"Fatal error", MB_OK | MB_ICONERROR);
  39. PostQuitMessage(0);
  40. }
  41.  
  42. hWnd = CreateWindowEx(0, L"¡Título!", L"¡Título!", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT,
  43.  640, 480, HWND_DESKTOP, NULL, GetModuleHandle(NULL), (void *)NULL);
  44.  
  45. if(hWnd = NULL) {
  46. MessageBox(NULL, L"Error creating a window!", L"Fatal error", MB_OK | MB_ICONERROR);
  47. PostQuitMessage(0);
  48. }
  49.  
  50. ShowWindow(hWnd, SW_SHOWDEFAULT);
  51.  
  52. PIXELFORMATDESCRIPTOR PFD;
  53. int choosenPFD;
  54.  
  55. memset(&PFD, NULL, sizeof(PIXELFORMATDESCRIPTOR));
  56. PFD.nVersion = 1;
  57. PFD.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  58. PFD.iPixelType = PFD_TYPE_RGBA;
  59. PFD.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  60. PFD.cColorBits = 24;
  61. PFD.cDepthBits = 16;
  62. PFD.iLayerType = PFD_MAIN_PLANE;
  63.  
  64. hDC = GetDC(hWnd);
  65.  
  66. choosenPFD = ChoosePixelFormat(hDC, &PFD);
  67.  
  68. if(!choosenPFD) {
  69. MessageBox(hWnd, L"Error choosing a pixel format (old)!", L"Fatal error", MB_OK | MB_ICONERROR);
  70. PostQuitMessage(0);
  71. }
  72.  
  73. if(!SetPixelFormat(hDC, choosenPFD, &PFD)) {
  74. std::clog << GetLastError();
  75. MessageBox(hWnd, L"Error setting a pixel format (old)!", L"Fatal error", MB_OK | MB_ICONERROR);
  76. PostQuitMessage(0);
  77. }
  78.  
  79. hRC = wglCreateContext(hDC);
  80.  
  81. if(!hRC) {
  82. MessageBox(hWnd, L"Error creating a OpenGL context (old)!", L"Fatal error", MB_OK | MB_ICONERROR);
  83. PostQuitMessage(0);
  84. }
  85.  
  86. if(!wglMakeCurrent(hDC, hRC)) {
  87. MessageBox(hWnd, L"Error linking a OpenGL context with a window!", L"Fatal error", MB_OK | MB_ICONERROR);
  88. PostQuitMessage(0);
  89. }
  90.  
  91. while(Msg.message != WM_QUIT) {
  92. if(PeekMessage(&Msg, hWnd, NULL, NULL, PM_REMOVE)) {
  93. TranslateMessage(&Msg);
  94. DispatchMessage(&Msg);
  95. }
  96.  
  97. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  98.  
  99.  
  100.  
  101. SwapBuffers(hDC);
  102.  
  103. std::this_thread::sleep_for(std::chrono::microseconds(11764));
  104. }
  105.  
  106. wglMakeCurrent(NULL, NULL);
  107. wglDeleteContext(hRC);
  108. ReleaseDC(hWnd, hDC);
  109. DestroyWindow(hWnd);
  110. UnregisterClass(L"¡Título!", GetModuleHandle(NULL));
  111.  
  112. return 0;
  113. }
  114.  
  115. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  116. switch(uMsg) {
  117. case WM_DESTROY:
  118. PostQuitMessage(0);
  119. }
  120.  
  121. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  122. }


« Última modificación: 8 Junio 2015, 05:10 am por Seyro97 » En línea

Carlos Peláez González. visita http://www.taringa.net/EnjoyC para muchos tutoriales!
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
funcion de opengl
Programación C/C++
mapers 2 2,074 Último mensaje 27 Octubre 2010, 06:10 am
por mapers
Error OpenGL.
Programación C/C++
BlackZeroX 3 3,858 Último mensaje 5 Marzo 2011, 20:57 pm
por BlackZeroX
OpenGL ( Error Luz ). No apunta a donde deberia.
Programación C/C++
BlackZeroX 0 1,706 Último mensaje 23 Julio 2011, 09:52 am
por BlackZeroX
[AYUDA] Error con función cargar archivo.
Programación C/C++
Black cracker 8 2,457 Último mensaje 3 Septiembre 2015, 15:17 pm
por someRandomCode
Ayuda error con la función getline
Programación C/C++
Guayavas 1 2,984 Último mensaje 8 Octubre 2017, 11:50 am
por ivancea96
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines