Jump to content
  • Advertisement

Archived

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

Perferati

OpenGL OpenGL and MDI MFC, I need help!!!

This topic is 2669 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, well after pulling my hair out for several hours I thought I would post my problem , maybe by the grace of god somebody can help. I am writing an MFC MDI application which uses OpenGL for its rendering View. I have a class called "GOpenGLView : public CView". In this class I have handlers for WM_CREATE, WM_DESTROY and WM_SIZE. I have also override PreCreateWindow and OnDraw. My problem is, that it compiles fine, runs fine, but when I create a new GL window, its just BLACK...i can''t see my sphere no matter how big I make it...i can''t see anything but black..if I change the glClearColor(...) it will be a different colour background...all my code is taken from various websites/code dumps which all make sense..i''ve written gl programs before and have never had such difficulty. I am at a loss and not sure what to do...I *really* don''t want to have to start this whole program from scratch. Obviously i don''t want to dump a whole lot of code here so if anyone thinks they might know what is wrong, i will post any relevant code...thanks for your help!

Share this post


Link to post
Share on other sites
Advertisement
What function draws the spheres? Are you sure it''s executed ever/often enough?

Try a quad in ortho mode instead of a sphere, it should be easier to get right.

Are you calling SwapBuffers? Is the view window redrawn? Are you sure all initialization steps are performed for the view window?

Do you have CS_OWNDC class style?

Do you have this problem with one or many GL windows?

Share this post


Link to post
Share on other sites
Here is my OnDraw function:

void GOpenGLView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
ASSERT_VALID(pDoc);

//Get client size
CRect clientRect;
GetClientRect(&clientRect);

//Set lighting and material model
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, m_fAmbientLight);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,m_fMaterialValue);

wglMakeCurrent(pDC->m_hDC,m_hGLRC);

//Enable lighting
glLightfv(GL_LIGHT0, GL_POSITION, m_fLightPos);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

//Set the viewport
glViewport(0, 0, clientRect.Width(), clientRect.Height());

//Projection mode / Clear matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

//Rotate Camera
glRotatef(0,0,1,0);

//Setup perspective projection
gluPerspective(40.0,(GLfloat)clientRect.Width()/(GLfloat)clientRect.Height(),5.0,1000.0);

DrawCube(); //<--Or sphere, nothing will show up

glFlush();
SwapBuffers(pDC->m_hDC);
wglMakeCurrent(pDC->m_hDC,NULL);
}

And my DrawCube() function :

void GOpenGLView::DrawCube()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//Postion camera
gluLookAt(0, 0, 3, //Eye Position
0, 0, -100, //LookAt Position
0,1,0); //Up Vector

glClear(GL_COLOR_BUFFER_BIT);

glShadeModel(GL_SMOOTH);

//ALL VERTICIE DRAWING HERE, CUT OUT FOR READABILITY
}


I don''t know if I should post any other routines...I am pretty sure I am setting the hDC properly before drawing, and I don''t have CS_OWNDC class style...where would I set this? I don''t know, im at a loss...

Share this post


Link to post
Share on other sites
Set CS_OWNDC in PreCreateWindow.

See if glGetError returns anything.

Remove the second wglMakeCurrent call, because it''s not needed.

Call wglMakeCurrent(hglrc) before any rendering in that context.

I would expect having multiple rendering contexts active simultaneously to be quite slow. Do you absolutely need this setup? You''ll be much better off with one RC and several viewports. Think about it.

Share this post


Link to post
Share on other sites
Hi, I'm try to do the same thing and only get black blank window. It's refreshable, but not show any of vertex draw in the OnDraw(); Co you have maybe simplest app in MFC MDI with OpenGL? Just regular white triangle is enough for me.

Cheers!

Share this post


Link to post
Share on other sites
This is a old thread from 2002. [url="../../user/32075-perferati/"]Perferati[/url] is dead and the posters are dead. There is no point in asking them for source code.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!