MFC Object Viewer + Bug = I don't like it !

Hi guys I’m trying to do a simple object viewer for my artist so he’ll be able to view the model with the textures he does without having my whole project.
BUT there is a problem…I can’t find out why my opengl code is not drawing anything in my SDI window…
In the OnPaint I do the code from the second nehe tutorial (very very VERY basic) just to make sure it’s not a camera or model probleme and still…there’s nothing drawing…BUT i can change the color of the glClear.
Could someone check my code and tell me why it’s not working ? you can get my code there http://pages.infinit.net/marcoars/lwviewer.zip
thanks a lot if you can enlighten me !
Left click darken the clear color and right click makes it more bright.

the init code is in InitGLContext() and the rendering code is in RenderScene()

do whatever you want to my code and if you make it work and have the proper explanations I’ll be very glad
thanks a lot !


Evil-Dog
Sleep is a waste of time

Hey guys please help hehehe !

I’d be happy to develop your code for you.

Start-up cost is $8,000 and then it’s $195 per hour.

I’m sorry if this sounds harsh, but I think posting your own code as a ZIP archive somewhere, and expecting someone else to find and fix your bug for you seems a little optimistic to me.

If it’s work-for-free, I prefer to do it on my own project, and/or in a public forum where more than one person can potentially learn from it.

If you debug the code on your own, it’d be excellent if you posted back here so we can all avoid the same bug that bit you.

Good luck!

That is outrageous! My fees are only $7999.99 and 128.99 and hour. I just don’t see how anyone would hire you over me jwatte!

As for the Q at hand, if you copied nehe’s code, and it don’t work, and you copied it exactly, and his works, and yours don’t then you need to re-read nehe’s code.

P.S, I hate MFC! Bah!

What the **** are you talking about dumb-ass ?
Look ! I have all my code already !
All I asked was if someone was kind enough to check if I forgot something that could cause my geometry to NOT RENDER !
I don’t ask you to develop my ****ing app !
damn…why do you bother checking on help forum if you’re the freakin cheap type !
I helped many people here ! I have a great engine going on but I’m working on this tool with MFC(which is new to me) and I ask for for some hint why it’s not working even with all my effort to make it work !
Sometimes you can get some help when you helped others before !
As I told you…don’t come in the forum if you want to get paid to help moron !
Thanks anyway !


Evil-Dog
Sleep is a waste of time

I was talking to jwate by the way…
I just took The rendering part fomr the second nehe tutorial instead of all heightmap and my billboards and all the stuff in my engine…Just to draw a simple white triangle and square
but still it’s not showing !
But I can change the glClear color interactively while the app is running…why my glClear works but my glBegin/glStuff/glEnd doesn’t work ? I don’t get it !


Evil-Dog
Sleep is a waste of time

jwatte does have a point…

This forum is here to help each other, but not to help debugging each others projects.

Second, it doesn’t seem you tried to solve it yourself.

To make my post just a little bit more helpfull, I can tell you without looking at the code that you forgot to set the viewport + projection matrix.
(well, that’s the most common problem… I’m just guessing)

btw. But of course you could also hire me to debug your little app for €180 per hour

  1. I set my projection matrix right (maybe not the viewport but I never did even with my whole engine and it’s working fine)
  2. What’s the difference between “posting a code sample and asking what’s wrong with it” (which I often see) and “posting the whole code cause it’s MFC and there’s a lot of event function and asking what’s wrong with it”
  3. If you don’t wanna help just shut the **** up…I can’t beleive I helped people here for a long time and when it’s my turn to ask for help people post stupid comments
  4. I’ll find it myself cause it seems it’s a “Discussion and arguing about NOT helping Forums” instead of “Discussion and help forums”

Thanks you VERY MUCH !

  1. If you would’ve set your viewport, you’d discovered that there’s something wrong…
  2. It’s not because it’s using MFC, it’s because you’re posting a project of 2.735 lines instead of 10 lines of sample code.
  3. Pfew, you’re hotbaked…
    Of course I’d like to help, see 2 for more info.
  4. I think you’re not getting the point… :stuck_out_tongue:

btw1. Check your ****ing width & height!
btw2. Check your ****ing resize function!
btw3. Check your ****ing gluPerspective call, you’re killing the zbuffer! (0.f for near plane!)
btw4. ****!
btw5. Hope this helps!

YOU’RE WELCOME!

[This message has been edited by richardve (edited 02-10-2002).]

As I said I don’t use glViewport (I don’t use it in my main project http://pages.infinit.net/marcoars and it works anyway I don’t need glViewport)

10 lines of MFC code doesn’t say anything since there’s so much event function and that the game loop is with the WM_TIMER event so there’s a lot of thing going on and I can’t show my code in 10 lines. Can you guys you get that ? If I post 10 or even 20 lines of code, you won’t see a damn thing of what could be wrong…MFC is freakin big and I’m new to it so I asked for a check to see if I was doing it good. Not to start a debate on “how much code should be post when someone needs help”

my size and height are ok
I don’t resize so there’s no resizing
my game loop is ok (I can change the color of the glClear while the app is running it means that the glClear function is applied on the good rendering context but the geometry won’t appears and that’s what I don’t understand)

I’ve been looking everywhere in my app for 3 days now to see if something’s missing somewhere.

All I need is a gentle soul who knows MFC and who is willing to check my code if he can see what I could do wrong.

Thanks for your replies but don’t write negative comments about “how my post is not good” ok I don’t need that !
I’ve helped before and now I ask others for help that’s it !


Evil-Dog
Sleep is a waste of time

Originally posted by Evil-Dog:
As I said I don’t use glViewport (I don’t use it in my main project http://pages.infinit.net/marcoars and it works anyway I don’t need glViewport)

You should.

10 lines of MFC code doesn’t say anything since there’s so much event function and that the game loop is with the WM_TIMER event so there’s a lot of thing going on and I can’t show my code in 10 lines. Can you guys you get that ?

Can you get that the ‘10 lines of code’ was just an example?

MFC is freakin big and I’m new to it so I asked for a check to see if I was doing it good.

And I just gave you all answers…

my size and height are ok

Your width and height are NOT ok, check your init code.

I don’t resize so there’s no resizing

And that’s your whole problem.

my game loop is ok (I can change the color of the glClear while the app is running it means that the glClear function is applied on the good rendering context but the geometry won’t appears and that’s what I don’t understand)

That’s because your viewport has the number zero (0) for both the width and height, check your init code.

I’ve been looking everywhere in my app for 3 days now to see if something’s missing somewhere.

You’ve not been searching good enough, check your init code.

All I need is a gentle soul who knows MFC and who is willing to check my code if he can see what I could do wrong.

I am a gentle cough soul cough who knows MFC and is trying to help you and has even checked your code, now go and check your init code.

Thanks for your replies but don’t write negative comments about “how my post is not good” ok I don’t need that !

Your post is not good, check your init code.

I’ve helped before and now I ask others for help that’s it !

Check your ****ing init code!

btw. Did I already told you that you should check your initialisation code?

Even though I hate you…I love ya !
hehe
That’s true my width and height are 0
I tried to follow your ****ty advise and i set a viewport and it worked hahahaha (I’m kidding your advise was not ****ty I’ll use glViewport too in my main project to be sure even tho it’s working without it)
the only problem is that I set the viewport with an arbitrary value since I don’t know how to get the window size but I’ll solve this in no time !
Thanks a lot I’m glad you helped
But anyway I think a “whole code post” is better than some part of codes.
That’s a shame that it caused some disagreement since it’s an helping forum !
anyway…thanks again !


Evil-Dog
Sleep is a waste of time

Originally posted by Evil-Dog:
Even though I hate you…I love ya !
hehe

the only problem is that I set the viewport with an arbitrary value since I don’t know how to get the window size

Thanks a lot I’m glad you helped
But anyway I think a “whole code post” is better than some part of codes.
That’s a shame that it caused some disagreement since it’s an helping forum !
anyway…thanks again !

Like I said, people do want to help you, but you have to show you did something yourself too instead of just posting it to a forum and saying “It doesn’t work, please fix this code for me”, THAT’s what I (and others) was trying to tell you.

Anyway, since you’re new to MFC, I’ll help you another bit

Go to the ClassWizard (CTRL+W) and add a WM_SIZE function from the ‘messages’ field (scroll down).
Press the ‘Edit Code’ button and add the following code:

// Don’t add this
CView::OnSize(nType, cx, cy);

// Do add this
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

float fAspect = (cy == 0) ? cx : (float)cx/(float)cy;

// Set your near clipping plane to 1.f instead of 0.1f
gluPerspective(45.0f, fAspect, 1.f, 100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glViewport(0, 0, cx, cy);

// TODO: Add your message handler code here
}

Argh, this ****ing forum removed those line breaks!

Thanks again !
But I’ve already done that hehehe


Evil-Dog
Sleep is a waste of time

You have hosed this SDI app up beyond belief.

This is your MFC Windows header.

#include <afxwin.h> // MFC core and standard components.

Don’t use window.h. I can’t believe this even compiled.

Don’t use glaux! There are plenty of bmp loaders floating around if you can’t write your own.

Why did you use OnPaint() when you are supposed to use OnDraw()?

Put your opengl stuff in the standard directories so that you don’t waste time of people who are trying to help you.

#include <GL/gl.h> // OpenGL include file
#include <GL/glu.h> // OpenGL Utilities include file

You are drawing the square over the triangle.

Pay attention to the other posters, you don’t know how set up an OpenGL viewing frustrum and you didn’t copy the stuff from NeHe correctly.

Don’t change the MFC SDI structure if you don’t know what you’re doing, e.g., OnSize, etc.

Try my website. http://www.mfcogl.com/

  1. Put this in your InitGLContext() in place of your stuff and delete your stuff.

    float width = rect.Width();
    float height = rect.Height();

    float aspect_ratio = (float)width/(float)height;

    glViewport(0,0,width,height); // Reset The Current Viewport

    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glLoadIdentity(); // Reset The Projection Matrix

    gluPerspective(45.0f,aspect_ratio,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window

    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    glLoadIdentity();

/* Your stuff
float fAspect = (rect.Height() == 0) ? rect.Width() : (float)rect.Width()/(float)rect.Height();
gluPerspective(45.0f, fAspect, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
*/

2)Call InitGLContext()in RenderScene() and it will work;

I can mail you a working version of your code, but it will cost you. I’ll let the rest of the group determine the price.

JP

“You have hosed this SDI app up beyond belief.”

huh ?

"This is your MFC Windows header.

#include <afxwin.h> // MFC core and standard components.

Don’t use window.h. I can’t believe this even compiled."

I tried without and opengl needed it

“Don’t use glaux! There are plenty of bmp loaders floating around if you can’t write your own.”

Glaux is fine for now

“Why did you use OnPaint() when you are supposed to use OnDraw()?”

OnPaint is ok

"Put your opengl stuff in the standard directories so that you don’t waste time of people who are trying to help you.

#include <GL/gl.h> // OpenGL include file
#include <GL/glu.h> // OpenGL Utilities include file"

that’s right I’ll do that (No need to take that arrogant style)

“You are drawing the square over the triangle.”

That was not the point of my posting…I already have a little 3D engine…I just took some basic rendering and played around with the translation.

“Pay attention to the other posters, you don’t know how set up an OpenGL viewing frustrum and you didn’t copy the stuff from NeHe correctly.”

1)My viewing frustrum is working in my main project like it is in the code i posted so I couldn’t know that it was wrong here.
2)I pay attention to other posters. i did like he said and it worked thanks to him. We are here to learn not to proof we’re the best like you seem to try to do. In fact you’re the one who don’t pay attention to other posters cause you didn’t see that my problem was fix thanks to richarve.
3)I didn’t copy the whole nehe code I took some rendering code and modify it to test what I as doing wrong.

"Don’t change the MFC SDI structure if you don’t know what you’re doing, e.g., OnSize, etc. "

As I said…I’m here to learn. If someone doesn’t try what he doesn’t know…he’ll do nothing. It’s simple isn’t it ?

Thank you anyway for trying to help but really…you don’t need to be arrogant.
Learning is the goal…not showing off.


Evil-Dog
Sleep is a waste of time

If you go back and read all of your posts, it seems that your more interested in fussing with people than you are in learning. You ask for help and then snap at all those that try to help you. I haven’t insulted you or made anything personal. I don’t see why you would thank people in one stroke and then insult them in the next. Those tips were not arrogance. If you don’t want to take advantage of them they are your problems, but most of them will come back to bite you.

I was 1) re-enforcing what richardve was explaining on setting up the OpenGL viewing frustrum because it didn’t seem to register and 2) showing you a way to fix your code without OnSize(), but apparently you missed that.

You also seem to need to have the last word.

ok ok…
look I’m sorry
you were right I was wrong thank you for helping me pals !

I was frustrated about people criticizing that I post my whole code which is a waste of time instead of just helping without criticizing. maybe people thought I was just sitting on my ass waiting for an answer. But that’s no the case I was trying to figure it out on my side too but because I never set a viewport and it always worked…I never thought to check that.

I’ll set my viewport forever hehe

And your comments looked like arrogant to me but I misjudged you if you tell me they were not.

May everyone lives in peace and have good times !

hehehe
Such an happy ending isn’t it ?


Evil-Dog
Sleep is a waste of time

Well, let me have the last word for now…

Originally posted by J P:
gluPerspective(45.0f,aspect_ratio,0.1f,100.0f);

I really can’t stand seeing this so much… why are people still using 0.1f for the near clipping plane??

It’s bad, it’s evil, it’s no good, and it’ll give you some very nice looking artifacts.

Pleeeaaase, use 1.f or higher

And IMNSHO WM_SIZE is good ™.

Originally posted by Evil-Dog:
I was frustrated about people criticizing that I post my whole code which is a waste of time instead of just helping without criticizing.

Next time, try posting it as a COTD at flipCode.
Free comments and fixes without asking anything.

maybe people thought I was just sitting on my ass waiting for an answer. But that’s no the case

Well, reread your first post a few more times and you’ll come to the same conclusion.

I was trying to figure it out on my side too but because I never set a viewport and it always worked…I never thought to check that.

It wasn’t only the viewport… (hint: those vertices should also being projected correctly)

Hmz, talking about offtopic…

/me kicks own *ss