Can someone please help me, i don’t know why my Code doesn’t work i am not getting any rendering context’s, choosepixelformat alway’s fails.
I am using MS VC++ 6.0 on a PIII 450, Geforce1 System but that should not be the reason since my code doesn’t get any valid
either software emulated or hardware pixelformat.
Please explain me my faults…
tnx in advance
#include “windows.h”
#include “gl/gl.h”
#define WNDCLASSNAME “WndClassName”
#define WNDNAME “WndName”
#define WNDX 0
#define WNDY 0
#define WNDWIDTH 640
#define WNDHEIGHT 480
#define WNDCOLORDEPTH 16
#define DEPTHBUFFER 16
#define ALPHABUFFER 0
#define STENCILBUFFER 8
#define ACCUMBUFFER 32
#define AUXILIARYBUFFER 0
HWND hMainWindow = NULL;
DEVMODE DevMode, OldScreen;
PIXELFORMATDESCRIPTOR pfd;
int nNumberOfPixelFormats = 0;
HDC hDC = NULL;
int pixelFormat;
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//local variables and identifiers
//main stuff
//process messages
switch(uMsg)
{
case WM_CREATE:
hDC = GetDC(hWnd);
if(hDC == NULL)
{
MessageBox(NULL, “Error”, “Error”, MB_OK);
return (0);
}
memset(&pfd, 0,
sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_SUPPORT_OPENGL |
PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 32;
pfd.iLayerType = PFD_MAIN_PLANE;
//here i get always 0 for pixelformat but why
pixelFormat = ChoosePixelFormat(hDC, &pfd);
if (pixelFormat == 0)
{
// Handle error here
MessageBox(NULL, “Failed to ChoosePixelFormat”, “Error”, MB_OK);
return (0);
}
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
//end
return (DefWindowProc(hWnd, uMsg, wParam,
lParam));
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
//local variables and identifiers
WNDCLASSEX WndClass;
HWND hWnd;
MSG Msg;
//main stuff
//Fill WNDCLASS Structure
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.hbrBackground =
GetStockObject(BLACK_BRUSH);
WndClass.hCursor =
LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon =
LoadIcon(NULL, IDI_APPLICATION);
WndClass.hIconSm = NULL;
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WindowProc;
WndClass.lpszClassName = WNDCLASSNAME;
WndClass.lpszMenuName = NULL;
WndClass.style =
CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
//Register Window
if(!RegisterClassEx(&WndClass))
{
return (0);
}
//Create Window
hWnd = CreateWindowEx(0, WNDCLASSNAME, WNDNAME, WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
WNDX, WNDY, WNDWIDTH, WNDHEIGHT, NULL, NULL, hInstance, NULL);
if(hWnd == NULL)
{
return (0);
}
//Save Window into a Global
hMainWindow = hWnd;
//Main MessageLoop
while(1)
{
if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)
!= 0)
{
//Message available
if(Msg.message == WM_QUIT)
{
break;
}
//Translate Message
TranslateMessage(&Msg);
//Dispatch Message
DispatchMessage(&Msg);
}
}
return (Msg.wParam);
}
[This message has been edited by powerpad (edited 09-10-2002).]