Archived

This topic is now archived and is closed to further replies.

Michelle

Z-axis

Recommended Posts

Sorry but I cant solve this probably very easy and lame question but... I tried to use http://www.codeguru.com/opengl/MG-opengl.zip But when I move my object on the z-axis nothing happens, until they disappear... Can someone please tell me why? And how to solve it... The init of the opengl part of the program is like this: int MySetPixelFormat(HDC hdc) { PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // size of this 1, // version number PFD_DRAW_TO_WINDOW | // support window PFD_SUPPORT_OPENGL | // support OpenGL PFD_DOUBLEBUFFER, // double buffered PFD_TYPE_RGBA, // RGBA type 24, // 24-bit color 0, 0, 0, 0, 0, 0, // color bits 0, // no alpha buffer 0, // shift bit 0, // no accumulation 0, 0, 0, 0, // accum bits 32, // 32-bit z- 0, // no stencil 0, // no auxiliary PFD_MAIN_PLANE, // main layer 0, // reserved 0, 0, 0 // layer masks }; int iPixelFormat; // get the device context''s best, available pixel format match if((iPixelFormat = ChoosePixelFormat(hdc, &pfd)) == 0) { MessageBox(NULL, "ChoosePixelFormat Failed", NULL, MB_OK); return 0; } // make that match the device context''s current pixel format if(SetPixelFormat(hdc, iPixelFormat, &pfd) == FALSE) { MessageBox(NULL, "SetPixelFormat Failed", NULL, MB_OK); return 0; } return 1; } int COpenGL::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here MySetPixelFormat(::GetDC(m_hWnd)); return 0; } And then the rendering: void COpenGL::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here HDC hdc = ::GetDC(m_hWnd); HGLRC hglrc; // TODO: Add your message handler code here glClearColor(0,0,0,0); glColor3f(1, 1, 1); if (hglrc = wglCreateContext(hdc)) { // try to make it the thread''s current rendering context if(wglMakeCurrent(hdc, hglrc)) { //render here glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glBegin(GL_TRIANGLES); glColor3f(1, 0, 0); glVertex3f(.5, 0, 0); glColor3f(0, 1, 0); glVertex3f(0, .5, 0); glColor3f(0, 0, 1); glVertex3f(-.5, 0, 0); glEnd(); SwapBuffers(hdc); } } wglMakeCurrent(NULL, NULL) ; ::ReleaseDC (m_hWnd, hdc) ; wglDeleteContext(hglrc); // Do not call CWnd::OnPaint() for painting messages } PLease please please please please help me!!!!

Share this post


Link to post
Share on other sites
I''m not sure what the problem is since I can''t quite follow the code (too tired), but you might try the NeHe site for some ideas. I used their tutorial to learn OpenGL, and moving in the z plane worked fine. It''s probably that you aren''t setting perspective projection.

The NeHe site is at http://nehe.gamedev.net/

Here''s what you should try in your initialization code:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(float)(4/3),0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

as well as

glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);

for an explanation of this code, go to NeHe, they''ve got some great OGL tutorials.

Share this post


Link to post
Share on other sites
And I have coded some win32 opengl stuff, like those tutorials on nehe, but nehe doesnt init their apps like I do now with:

wglCreateContext();
wglMakeCurrent()

You may wonder why I use these functions if they doesnt work as I want, but it´s the only good solution I have found on combining mfc and the appwizard with opengl ... :/

Share this post


Link to post
Share on other sites
Uhm well this code looks a bit strange... You should repaint (or maybe rerender ) your scene each time after calling such functions as glEnable, glTranslatef, glRotatef and so on. So glBegin/glEnd sequence must be called multiple times, not once. And you really shouldn''t recreate rendering context each time before rendering since you don''t destroy it after

Share this post


Link to post
Share on other sites
Winter:Well of course I do that ...

Can someone please take a look at my code and tell me what''s wrong.. You can find the workspace on:
ftp://gamedev:gamedev@mreklund.no-ip.com:500

If you press down the Z radio button, and drag the x slider you´ll see what''s the problem... When you drag that slider you change the z position for the triangle, nothing happens until the triangle disappears...

A account on my ftp if someone solves my problem =)

Share this post


Link to post
Share on other sites