Can you tell me what i've missed or did wrong?

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

You don’t create a GL context, so the openGL functions will fail. Look at the wglCreateContext() documentation.

You should use a windowing api like glut or sdl (i recommend sdl). They’re cross platform and the windows api is horrible, no one in their right minds should use it :stuck_out_tongue:

GLUT and SDL depend on external DLLs being available so they’re not always ideal, and being cross platform is only an advantage if you’re writing a cross platform app.

Just sayin’. :slight_smile:

Yea but they’re easier to use. And whats wrong with dlls? :s everything has to use them, and dll’s can be a good way to split up a large program if not all of the parts of it are needed at once.