<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'Help needed with my openGL code' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'Help needed with my openGL code' posted on the 'OpenGL' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Tue, 18 Jun 2013 18:54:06 -0700</pubDate>
    <lastBuildDate>Tue, 18 Jun 2013 18:54:06 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>Help needed with my openGL code</title>
      <link>http://www.programmersheaven.com/mb/openGL/417097/417097/help-needed-with-my-opengl-code/</link>
      <description>Hello guys!&lt;br /&gt;
&lt;br /&gt;
I've been working on my own openGL window for a while now..&lt;br /&gt;
I can compile it in dev c++ without errors, but it refuses to display my window.&lt;br /&gt;
Hope you can tell me what I've doing wrong or what I've missed.&lt;br /&gt;
&lt;br /&gt;
Here is the code:&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
#include &amp;lt;windows.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;stdarg.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;gl/gl.h&amp;gt;
#include &amp;lt;gl/glu.h&amp;gt;
#include &amp;lt;gl/glaux.h&amp;gt;
#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(&amp;amp;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(&amp;amp;msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
done = true;
}
else
{
DispatchMessage(&amp;amp;msg);
TranslateMessage(&amp;amp;msg);
}
SwapBuffers(hDC);
DrawGLScene();
}
return (msg.wParam);
}
}

&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
~Xrid3r&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/openGL/417097/417097/help-needed-with-my-opengl-code/</guid>
      <pubDate>Tue, 08 Jun 2010 12:04:00 -0700</pubDate>
      <category>OpenGL</category>
    </item>
    <item>
      <title>Re: Help needed with my openGL code</title>
      <link>http://www.programmersheaven.com/mb/openGL/417097/417601/re-help-needed-with-my-opengl-code/#417601</link>
      <description>A couple of items appear to be missing...unless you just didn't include them in your post. I didn't see where you called ChoosePixelFormat, SetPixelFormat, wglCreateContext, and wglMakeCurrent. Without these things, you have no context to render to. As a matter of fact, you initialize hDC to NULL, but I don't see where you attach it to an actual device context. I'm more familiar with MFC, but you need something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
        HDC hDC = hWnd-&amp;gt;GetSafeHdc();

        int nPixelFormat = ChoosePixelFormat(hDC, &amp;amp;pfd);
	SetPixelFormat(hDC, nPixelFormat, &amp;amp;pfd);

	hRC = wglCreateContext(hDC);
	wglMakeCurrent(hDC, hRC);
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
This, of course, must be done after creating your main window, but before any other openGL calls.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/openGL/417097/417601/re-help-needed-with-my-opengl-code/#417601</guid>
      <pubDate>Thu, 01 Jul 2010 18:20:00 -0700</pubDate>
      <category>OpenGL</category>
    </item>
  </channel>
</rss>