Hi, I have kept quiet for a week or 2 now, and think I have learnt a fair amount of the basic stuff I need to know. Now, I am stuck again, and it has to be something really simple, probably a case of not seeing the wood for the trees !
I am trying to set up my drawing area for a coordinate based system that I can relate to (i.e. 640 * 480), and not just the seemingly abitrary opengl units. (I got teh example from someone on heres source code, just to see how it was done)
My code below however does not work, when I think it should. I even copied someone elses code that does work using a similar method, and can''t get that to work either.
Here is my initialisation function.
PIXELFORMATDESCRIPTOR pfd;
int n;
HGLRC hrc;
GLfloat fMaxObjSize, fAspect;
GLfloat fNearPlane, fFarPlane;
ASSERT(m_pDC != NULL);
if (!bSetupPixelFormat(m_pDC))
return;
// Interrogates the Pixel Format to see if a Palette is needed.
n = ::GetPixelFormat(m_pDC->GetSafeHdc());
::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
//If a Palette is needeed, then create one.(256 Colours Only)
//Detect if Needed by Anding the Value in the Data flags and the Need Palette Flag
if ((pfd.dwFlags & PFD_NEED_PALETTE))
{
CreateRGBPalette(m_pDC);
}
// create a rendering context and make it current
hrc = wglCreateContext(m_pDC->GetSafeHdc());
wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);
//Clear the Depth Buffer
glClearDepth(1.0f);
//Enable OGL using the Depth Buffer for comparisons
glEnable(GL_DEPTH_TEST);
//Initialise OpenGL for 2d
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f,640.0f,0.0f,480.0f,-10.0f,10.0f);
glMatrixMode(GL_MODELVIEW);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_TEXTURE_2D);
//Select the GL Projection Matrix (Stack)
glMatrixMode(GL_PROJECTION);
//Reset Identity Matrix
glLoadIdentity();
}
and my draw scene function...
int CMyOgl::DrawGLScene()
{
static BOOL bBusy = FALSE;
if(bBusy)
return TRUE;
bBusy = TRUE;
//Setup Drawing Area Back Colour
glClearColor(m_BackColour.fRed, m_BackColour.fGreen, m_BackColour.fBlue, m_BackColour.fAlpha);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Reset the Drawing Point to the Centre of the screen
glLoadIdentity();
glColor3f(0.5f,0.5f,0.5f);
glBegin(GL_LINES);
glVertex3f(160.0f,120.0f,0.0f);
glVertex3f(480.0f,120.0f,0.0f);
glVertex3f(480.0f,120.0f,0.0f);
glVertex3f(480.0f,360.0f,0.0f);
glVertex3f(480.0f,360.0f,0.0f);
glVertex3f(160.0f,360.0f,0.0f);
glVertex3f(160.0f,360.0f,0.0f);
glVertex3f(160.0f,120.0f,0.0f);
glEnd();
SwapBuffers(wglGetCurrentDC());
bBusy = FALSE;
glFlush();
return TRUE;
}
If anyone can offer me any hints or even fix my probelm I''ll be very greatful.
As an aside, if I set my system up in this manner and draw in teh z plane at 0, is there an easy way of finding out how the coordinates I have set will change if I draw in another z plane, or have I misunderstood something fundamental ?
TYVMIA,
Bp.