mikeman: It still doesn't work. But I appreciate the help you've given me so far. I'll post some codes on how I set up OpenGL and see if you guys could spot any problems. =p
void Win32Window::setupPixelFormat(){ PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size 1, // version PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER, // support float-buffering PFD_TYPE_RGBA, // color type mBits, // prefered color depth 0, 0, 0, 0, 0, 0, // color bits (ignored) 0, // no alpha buffer 0, // alpha bits (ignored) 0, // no accumulation buffer 0, 0, 0, 0, // accum bits (ignored) 16, // depth buffer 0, // no stencil buffer 0, // no auxiliary buffers PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0, // no layer, visible, damage masks }; SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);}
void Win32Window::setupPalette(){ int pixelFormat = GetPixelFormat(hDC); PIXELFORMATDESCRIPTOR pfd; LOGPALETTE* pPal; int paletteSize; int redMask, greenMask, blueMask; int i; DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); if (pfd.dwFlags & PFD_NEED_PALETTE) paletteSize = 1 << pfd.cColorBits; else return; pPal = (LOGPALETTE*)LocalAlloc(LPTR, sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY)); pPal->palVersion = 0x300; pPal->palNumEntries = (short)paletteSize; // build a simple RGB color palette redMask = (1 << pfd.cRedBits) - 1; greenMask = (1 << pfd.cGreenBits) - 1; blueMask = (1 << pfd.cBlueBits) - 1; for (i=0; i<paletteSize; ++i) { pPal->palPalEntry.peRed = (BYTE)( (((i >> pfd.cRedShift) & redMask) * 255) / redMask); pPal->palPalEntry.peGreen = (BYTE)( (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask); pPal->palPalEntry.peBlue = (BYTE)( (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask); pPal->palPalEntry.peFlags = 0; } hPalette = CreatePalette(pPal); LocalFree(pPal); if (hPalette) { DeleteObject(SelectPalette(hDC, hPalette, FALSE)); RealizePalette(hDC); }
void Win32Window::create(){ hDC = GetDC(hWnd); setupPixelFormat(); setupPalette(); hGLRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hGLRC); if (hGLRC == 0) { throwEx(Exception::INTERNAL_ERROR, "Error creating OpenGL window", "Win32Window::create"); }}
void RenderSystem::initialise(){ mFaceCount = mVertexCount = 0; glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_SMOOTH); glEnable(GL_COLOR_MATERIAL); glShadeModel(GL_SMOOTH); ImageCodec::loadImageCodecs(); Material* mat = (Material*) MaterialManager::getInstance().create("white"); mat->setShininess(16.0f); mat->setAmbient(0.5f, 0.5f, 0.5f); mat->setSpecular(1.0f, 1.0f, 1.0f); mat->setDiffuse(0.5f, 0.5f, 0.5f); loadExtensions();}