   Problem with my openGL code
  Hello guys!I've been working on my own openGL window for a while now..I can compile it in dev c++ without errors, but it refuses to display my window.Hope you can tell me what I've doing wrong or what I've missed.Here is the code:#include <windows.h>#include <stdlib.h>#include <stdarg.h>#include <stdio.h>#include <gl/gl.h>#include <gl/glu.h>#include <gl/glaux.h>#include "time.h"LRESULT CALLBACK WndProc(HWND hWND,UINT umsg,LPARAM lParam,WPARAM wParam);HGLRC hRC = NULL;HDC hDC = NULL;HWND hWnd = NULL;HINSTANCE hInstance;bool active = true;bool keys[256];GLvoid ResizeGLScene(GLsizei width,GLsizei height){if(height == 0){height = 1;}glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0f,(GLfloat)width / (GLfloat) height,0.1f,100.0f);glMatrixMode(GL_MODELVIEW);glLoadIdentity();}int InitGLScene(GLvoid){glClearColor(0.0f,0.0f,0.0f,0.23f);glClearDepth(2.0f);glEnable(GL_DEPTH_TEST);glDepthFunc(GL_LEQUAL);glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);return true;}int DrawGLScene(GLvoid){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();glTranslatef(0.23f,0.23f,0.23f);glBegin(GL_QUADS);glVertex3f(0.20f,0.20f,0.20f);glVertex3f(0.20f,-0.20f,0.20f);glVertex3f(-0.20f,0.20f,0.20f);glVertex3f(-0.20f,-0.20f,0.20f);glVertex3f(-0.20f,-0.20f,0.20f);glVertex3f(0.20f,-0.20f,0.20f);glVertex3f(-0.20f,0.20f,0.20f);glVertex3f(0.20f,0.20f,0.20f);glVertex3f(0.20f,0.20f,0.20f);glVertex3f(0.20f,-0.20f,0.20f);glVertex3f(-0.20f,0.20f,0.20f);glVertex3f(-0.20f,-0.20f,0.20f);glVertex3f(0.20f,0.20f,0.20f);glVertex3f(0.20f,-0.20f,0.20f);glVertex3f(-0.20f,0.20f,0.20f);glVertex3f(-0.20f,-0.20f,0.20f);glVertex3f(0.20f,0.20f,0.20f);glVertex3f(0.20f,-0.20f,0.20f);glVertex3f(-0.20f,0.20f,0.20f);glVertex3f(-0.20f,-0.20f,0.20f);glVertex3f(0.20f,0.20f,0.20f);glVertex3f(0.20f,-0.20f,0.20f);glVertex3f(-0.20f,0.20f,0.20f);glVertex3f(-0.20f,-0.20f,0.20f);glEnd();}bool drawGLScene(char *title,int width,int height,int bits){GLuint PixelFormat;DWORD dwstyle;DWORD dwExstyle;WNDCLASS wc;RECT windowRect;windowRect.left = (long) 0;windowRect.top = (long) height;windowRect.right = (long) 0;windowRect.bottom = (long) width;hInstance = GetModuleHandle( NULL );wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;wc.lpfnWndProc = (WNDPROC) WndProc;wc.cbClsExtra = 0;wc.cbWndExtra = 0;wc.hbrBackground = NULL;wc.hInstance = hInstance;wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);wc.hCursor = LoadCursor(NULL,IDC_ARROW);wc.lpszMenuName = NULL;wc.lpszClassName = "OPENGL";if(!RegisterClass(&wc)){MessageBox(NULL,"Could not find the current register class","REGISTER ERROR",MB_OK | MB_ICONINFORMATION);return false;}if(hWnd != CreateWindowEx(dwstyle,"OPENGL",title,WS_CLIPCHILDREN |WS_CLIPSIBLINGS |dwExstyle,0,0,windowRect.top-windowRect.left,windowRect.bottom-windowRect.right,NULL,NULL,hInstance,NULL)){MessageBox(NULL,"Could not find the current window", "Window ERROR", MB_OK | MB_ICONSTOP);return false;}static PIXELFORMATDESCRIPTOR pfd= {sizeof(PIXELFORMATDESCRIPTOR),1,PFD_SUPPORT_OPENGL |PFD_DRAW_TO_WINDOW |PFD_TYPE_RGBA,PFD_DOUBLEBUFFER,bits,0, 0, 0, 0, 0, 0,0,0,16,0,0,PFD_MAIN_PLANE,0, 0, 0,};InitGLScene();SetFocus(0);DrawGLScene();ShowWindow(hWnd,SW_SHOW);SetForegroundWindow(hWnd);SetFocus(hWnd);}LRESULT CALLBACK WndProc(HWND hWnd,UINT umsg,LPARAM lParam,WPARAM wParam){switch(umsg){case WM_SYSCOMMAND:switch(wParam){case SC_MONITORPOWER:case SC_SCREENSAVE:break;};case WM_KEYDOWN:keys[wParam] = true;break;case WM_KEYUP:keys[wParam] = false;break;};case WM_RESIZE:ResizeGLScene(LOWORD(lParam),HIWORD(wParam));break;return DefWindowProc(hWnd,umsg,lParam,wParam);}int WINAPI WinMain(HINSTANCE hIntance,HINSTANCE hPrevInst,LPSTR iCmdLine,int iCmdShow){MSG msg;bool done = false;drawGLScene("Mickes",640,480,16);while(!done){if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){if(msg.message == WM_QUIT){done = true;}else{DispatchMessage(&msg;TranslateMessage(&msg;}SwapBuffers(hDC);DrawGLScene();}return (msg.wParam);}}~Xrid3r   
Why you shouldn't use Dev-C++.It looks like that code is based on code from here. You should compare it and see where the differences are.One problem is that the last return statement is inside the while loop, so the program exits immediately.   ;  @Gage64Thanks for the information, but I prefer to use the old Dev-C++.Yes, it is based on the nehe code.. I trying to make my own version of it without the error handlers and fullscreen mode..I also tried to move the last return statement outside the loop, but it still refuse to display my window. Any other suggestions?~Xrid3r   ;  Your not setting up the pixel format correctly, actually, you dont seem to be setting it up at all, "pfd" is declared but never used as far as I can tell, so you cant begin drawing yet. Lookup PIXELFORMATDESCRIPTOR's use.drawGLScene() seems to be doing a lot of initializing and setup, yet you call it draw? Not sure why, it shouldnt be drawing anything till setup correctly,you also make a DrawGLScene() call in there, not sure why.   ;  This line:if(hWnd != CreateWindowEx(...doesn't really make sense. You probably want to assign the return value to hWnd, and then check if hWnd is NULL.   ;  try looking at some of the SDL examples? (not on every nehe tutorial but some)?#include <cmath>#include <iostream>#include <SDL/SDL.h>#include <SDL/SDL_opengl.h>;  @Gage64Yes that is true.. My mistake, I believe it should be:if(!(hWnd = CreateWindowEx(..Now it entering my error handler which says "Can't create the window".. Any suggestion why it entering the error handler and refuses to display the window?@NumberXaeroWould it be a good idea to assign PIXELFORMATDESCRIPTOR to "pdf" so you can assign the return value and check if it's NULL, like @Gage64 suggest?@PrestoChungHmm.. What is the afford with SDL, if there are any?~Xrid3r   ;  In all seriousness I suggest you start again.First you need a half decent IDE/compiler, one you can rely on, I recommend Visual C++ 2010 Express, it's completely free and hands down the best choice for C++ on Windows. There really is no valid reason to still be using DevC++ these days, none at all.Second I suggest you take some time to learn a bit about what's going on, people don't get anywhere being "copy-and-paste coders" I'm afraid but that's exactly the sort of practice that sites such as Nehe foster. NeHe samples are not exactly regarded as examples of best practice either - there is some extremely weird stuff going on in that code (GLvoid, glaux, int return types on functions returning bool values, etc).I once wrote a high-level overview of how to setup OpenGL which you can use to get started:Quote:An overview of a typical Win32/OpenGL setup process is this:Win32 Stuff1) Create a window class (WNDCLASSEX) instance and register it (RegisterClassEx). N.B. This holds a pointer to the WndProc procedure (the window's event handler).2) Create a window (CreateWindowEx) to retrieve a HWND handle.3) If you that to go fullscreen then create a DEVMOVE instance and use it select a screen resolution by calling ChangeDisplaySettings. Otherwise, if you want to keep it windowed, skip this step.4) Retrieve a device context using the window's handle with the GetDC function.5) Create a pixel format descriptor (PIXELFORMATDESCRIPTOR) and use it to find a compatible pixel format using ChoosePixelFormat.6) Set this pixel format to the window device using SetPixelFormat.WGL Stuff7) Create an OpenGL rendering context from the window's device using wglCreateContext.8) Set this context as the one to use, with: wglMakeCurrent.Making it visible9) Now the window is all setup and ready to use; unless you said otherwise, the window is hidden by default, so call ShowWindow to make it visible.OpenGL stuffIt's all ready to go, OpenGL provides default values for everything. You do normally configure different things though, like matrices, texturing etc. I won't go into this as it's all dependant on what exactly you want to do.Shutting down1) Return the resolution to normal if you changed it for fullscreen mode: ChangeDisplaySettings(NULL, 0);2) Release the rendering context: wglMakeCurrent(NULL, NULL);3) Delete the rendering context: wglDeleteContext( hRC );4) Release the device context: ReleaseDC(hWnd, hDC);5) Kill the window: DestroyWindow(hWnd);6) I also like to unregister the window class at the end of the application (UnregisterClass), but it's superfluous.Try writing the setup code on your own, feel free to examine multiple tutorials to judge how to set things up properly, also Google for the functions and structures involved to find their documentation for crucial information that you just don't get told in tutorials.A good thing to remember is that tutorials should only ever be used as reference, they should be treated with suspicion unless you know the details are backed up by the documentation or, at the very least, numerous reputable sources. One thing you never do is take the code as verbatim on the assumption that it is well written or in any way shape or form demonstrates good practice or even the way that real-life applications are written - NeHe code is a good example of this, it's not pleasant C++ at all. Best thing to do is the warm up those brain cells - think - and write the code in a sensible way and in a normal way like you would do any other code, calling functions because you know they need to be called and not because a tutorial (typically written by a beginner anyway) has told you to.Good Luck [smile]   ;  For situation like this I will recommend SFMLFree and easy to setup opengl windows, don't have to mess with this Win32 api stuff.   ;freeglut is also a good option. It's more lightweight than SFML, which may or may not be desirable.   