PDA

View Full Version : MFC Object Viewer + Bug = I don't like it !



Evil-Dog
02-09-2002, 02:19 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif
thanks a lot !

----------------------------------------
Evil-Dog
*Sleep is a waste of time*

Evil-Dog
02-09-2002, 08:12 PM
Hey guys please help hehehe !

jwatte
02-10-2002, 08:19 AM
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!

Elixer
02-10-2002, 09:51 AM
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! http://www.opengl.org/discussion_boards/ubb/wink.gif


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. http://www.opengl.org/discussion_boards/ubb/smile.gif

P.S, I hate MFC! Bah!

Evil-Dog
02-10-2002, 09:55 AM
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*

Evil-Dog
02-10-2002, 09:59 AM
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*

richardve
02-10-2002, 01:03 PM
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 http://www.opengl.org/discussion_boards/ubb/wink.gif

Evil-Dog
02-10-2002, 01:42 PM
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 !

richardve
02-10-2002, 02:50 PM
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.. :p


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).]

Evil-Dog
02-10-2002, 03:15 PM
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*

richardve
02-10-2002, 03:28 PM
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! http://www.opengl.org/discussion_boards/ubb/wink.gif


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

Evil-Dog
02-10-2002, 04:12 PM
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*

richardve
02-10-2002, 04:50 PM
Originally posted by Evil-Dog:
Even though I hate you....I love ya !
hehe

http://www.opengl.org/discussion_boards/ubb/smile.gif


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 http://www.opengl.org/discussion_boards/ubb/wink.gif

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
}

richardve
02-10-2002, 04:51 PM
Argh, this ****ing forum removed those line breaks!

Evil-Dog
02-10-2002, 07:15 PM
Thanks again !
But I've already done that hehehe http://www.opengl.org/discussion_boards/ubb/smile.gif

-----------------------------------------
Evil-Dog
*Sleep is a waste of time*

J P
02-11-2002, 02:43 PM
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

Evil-Dog
02-11-2002, 03:56 PM
"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*

J P
02-11-2002, 05:01 PM
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.

Evil-Dog
02-11-2002, 05:20 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif
Such an happy ending isn't it ?

---------------------------------------
Evil-Dog
*Sleep is a waste of time*

richardve
02-11-2002, 08:14 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif


And IMNSHO WM_SIZE is good (tm).



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. http://www.opengl.org/discussion_boards/ubb/wink.gif



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

Adrian
02-11-2002, 11:33 PM
richardve, can you explain why 0.1f is bad? I thought that the important number is the ratio between the near and far plane. Isn't setting near and far to 0.1 and 100 the same in terms of z buffer resolution as using 1 and 1000? With a 32bit z buffer I have found I can set the near and far to 0.01 and 1000.

richardve
02-12-2002, 12:37 AM
0.1f is bad because you loose precision, so you're killing the depth buffer.

0.1 and 100 looks like it's the same as 1 and 1000, but it's not, because of the way floats work.

You can probably find more about it when doing a search here at these boards.

[sorry, short answer.. have to catch the train in a few minutes]

p9931734
02-12-2002, 07:15 AM
yeah, i agree with richardve. i have personal experience such a problem. the .1f will detort the texture on your model and causes the viewport to display objects which lie behind another( hence seeing two objects instead of one).

Evil-Dog
02-12-2002, 07:58 AM
richardve Flipcode is not good idea for whole code post ! hahaha I should try that next time !
hehehe (I'll be pulverized by the critics on COTD lol)

talking abouit near and far clipping plane
I agree that with 0.1f I got ugly distortion for far polygons....but If I set it to 1 I'll lose near polygons....I mean....suppose my scale is 1 unit = 1 meter... everything nearer that 1 meter will be clipped no ?

Evil-Dog
02-12-2002, 08:00 AM
Should I use a scale of 1 unit = 1 centimeter to solve this problem ?

Coconut
02-12-2002, 09:04 AM
Originally posted by Evil-Dog:
Should I use a scale of 1 unit = 1 centimeter to solve this problem ?

Evil-Dog, this is not an unit issue. I suggest you do a search on the beginner forum. I just did a search on "near clip", and a lot of people answered similar questions already.
I also find people are a lot more patient in the beginner forum, so next time you may want to post your project on that forum first.


[This message has been edited by Coconut (edited 02-12-2002).]

Evil-Dog
02-12-2002, 11:38 AM
I understand that it's a ratio near plane/far plane
but how can I achieve to have a very far view without clipping what is near ?
like having near object clipped at 1 and far object clipped at 100 000 (100 km)
if I set those value I'll get ugly polygons merging...glitches...ugly stuff you know hehehe
What can we do to counter this clipping-interval/polygon-quality ratio problem ?

------------------------------------
Evil-Dog
*Sleep is a waste of time*

Coconut
02-12-2002, 12:30 PM
Why do you want to draw two things, one is 1 mm in front of your eyes, and one is 100000km from you precisely?
What application do you have?

J P
02-12-2002, 02:54 PM
--------------------------------------------------------------------------------
Originally posted by richardve:

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


--------------------------------------------------------------------------------

0.1f for the near clipping plane is used in NeHe Lesson 3 (possibly other lessons) which is what was used by the OP. You might point this out to NeHe.

I haven't noticed any artifacts.

If you can produce some evil in a demo/tutorial, I'll post it as a warning to all.

Evil-Dog
02-12-2002, 03:48 PM
I don't think 0.1f for near clipping plane is bad.
it seems the ratio is bad...not the value itself...

and coconut don't exagerate what I said please hehehe

suppose I have a scale of 1 unit = 1 meter
I want something visible at 1 cm
and also visible at 1 km
so with my scale, that makes the near clipping at 0.01f (1 meter / 100 = 1 cm) and my far clipping at 1000 (1000 meters = 1 km hehehe)
take a terrain engine for example
isn't it possible to do this without having distortion for far object ?

------------------------------------
Evil-Dog
*Sleeping is a waste of time*

richardve
02-13-2002, 01:33 PM
Originally posted by J P:
0.1f for the near clipping plane is used in NeHe Lesson 3 (possibly other lessons) which is what was used by the OP. You might point this out to NeHe.

I haven't noticed any artifacts.

If you can produce some evil in a demo/tutorial, I'll post it as a warning to all.


Good idea, I'll do that when I've got the time for it.

/me bookmarks this topic..

Evil-Dog
02-13-2002, 05:16 PM
Hey guys...can someone answer to my question.
Now that you say that the ratio near/far clipping can cause distortion I wonder...
What if I want an object visible at 1 cm and another object visible (without distortion) at 1 km ?
What is the proper way to deal with that ratio problem ?

-----------------------------------
Evil-Dog
*Sleep is a waste of time*

chowe6685
02-13-2002, 06:00 PM
Well, you could use two frustrums. generate one with a near of .1 and a far of 10.0, draw everything in that range, then a second from 10.0 to 1000.0, that should solve the problem

Evil-Dog
02-13-2002, 07:50 PM
That seems to be a good solution !
thank you for your good idea !

---------------------------------------
Evil-Dog
*Sleep is a waste of time*

Eric
02-14-2002, 01:05 AM
Originally posted by chowe6685:
Well, you could use two frustrums. generate one with a near of .1 and a far of 10.0, draw everything in that range, then a second from 10.0 to 1000.0, that should solve the problem

Shouldn't he do that with decreasing depth values ????

I think that if you use such an algorithm, you have to clear the Z-Buffer between two ranges (otherwise the Z values will conflict, as they depend on the range !).

If you draw from close to far and clear the Z-Buffer, the objects that are close to the viewer will be erased by the ones that are far.

On the other hand, if you draw the farthest objects first, clear the Z-Buffer and draw the closest ones, everything will work (that's the Painter algorithm with multiple passes...).

Regards.

Eric

fritzlang
02-14-2002, 01:12 AM
is this the advanced section?

Evil-Dog
02-14-2002, 09:48 AM
Very constructive comment fritzlang.
continue like this you'll help a lot of people !
*sigh*

Eric thank you for the advise I'll work on that.

-----------------------------------------
Evil-Dog
*Sleep is waste of time*

fritzlang
02-14-2002, 11:47 AM
Ok you have a point there,
I apologize.

Evil-Dog
02-14-2002, 12:32 PM
It's ok dude http://www.opengl.org/discussion_boards/ubb/smile.gif
Sometimes I don't post in the right forum...or the subject change during the discussion...things happen...

Do you have a solution for the clipping ratio problem ?

-------------------------------------
Evil-Dog
*Sleep is a waste of time*

richardve
02-16-2002, 04:49 PM
Read this article: http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

richardve
02-20-2002, 04:54 AM
Originally posted by richardve:
Good idea, I'll do that when I've got the time for it.

/me bookmarks this topic..

Hah!

I've just created a little app, which displays a simple hemisphere (was actually a small skydome-test, for use in my engine)

Anyway, I just remembered this topic again, so I made a small screenshot, just to show you people how worse those artifacts can get, and that you are REALLY killing your depthbuffer:

http://www.richardve.f2s.com/sd.png

Hm, actually it looks pretty artistic http://www.opengl.org/discussion_boards/ubb/smile.gif


btw. Like I said, when I've got the time for it, I'll create some tutorial and send it to Jeff (NeHe)
Don't know if he'll use it.. but I think that's the only way to let all those (new) people know they shouldn't set their near clipping plane to a value less than 1.f

richardve
02-20-2002, 04:56 AM
argh, 5h!11y forum!

*click here to see the screenshot* (http://www.richardve.f2s.com/sd.png)