OPENGL & MFC GURUS (or not)......HELP!
Hi there.
Okay. trust me when I say this, but I have probably read over almost every single relevant tutorial i could find...so many..that that every link in the first 20 pages of google that show up when I search for help have been clicked!!! so I was hoping somebody out here could help me :( PLEAAAAAAAAAAASE...I'm using visual studio 6.0 to do this...and im only working with 2D graphics in openGL...NO 3D MUMBO JUMBO IS NEEDED AT ALL! JUST 2D...JUST 2D!
I have a 2 part question:
1) How do I use MFC to handle mouse messages that will let me draw openGL graphics everytime the mouse is clicked?
for example...whenever the user clicks the screen, a vertex appears at that spot.
2) Along the same lines, how do I continue to manipulate that point by selecting it, deleting it, moving it, changing its colour, etc etc?
So to reiterate, ALL I want to do is make an openGL DOT (or a line, or a triangle, or a rectangle, or etc etc etc) appear everytime I click on the screen! THAT'S IT! Nothing more, and nothing less. I've come across a million tutorials on lighting, and shading, and rotating BLAH BLAH BLAH....but i just want to know how to make my application mouse interactive!
I just cant seem to get started on the mouse handling..i've read about message maps and mouse hooks in MFC, but i just can't seem to put the two and two together! ANY HELP WILL BE GRRRRRRRREATLY appreciated.
Btw, I have already taken care of the necessary initializations (i think) like setting the pixelformat and making the rc current, etc etc.....all i need to know is how to make it interactive.
Thanks in advance :D
- mary
# 1 Re: OPENGL & MFC GURUS (or not)......HELP!
Take a look at the followings.
An MFC OpenGL Polygon Tessellation Demo (http://www.dev-archive.com/Cpp/G-M/opengl/openfaq/article.php/c9137/)
How to make an MFC application with an OpenGL viewport (http://home.planet.nl/~monstrous/tutMFC.html)
Graphics Programming Using OpenGL and MFC - Whitepaper (http://www.cswl.com/whiteppr/tutorials/opengl.html#layout)
Compiling OpenGL Code with MFC (http://www.gamedev.net/reference/articles/article1802.asp)
OpenGL in a Mfc dialog (http://steinsoft.net/index.php?site=Programming/Tutorials/opengl_dialog)
Setting up OpenGL with Mfc (http://steinsoft.net/index.php?site=Programming/Tutorials/mfcopengl)
Drawing Image RGB Color Distribution Using OpenGL (http://www.dev-archive.com/Cpp/G-M/opengl/article.php/c2691/)
Ejaz at 2007-11-10 3:50:53 >

# 2 Re: OPENGL & MFC GURUS (or not)......HELP!
Hi Ejaz,
First of all, I just wanna say THANK YOU SOOO MUCH for the fast reply! Really appreciate that...and secondly PAKISTANI PRIIIIIIDE hahah, hey how is the weather over there? I haven't been back for quite some time now..
Anyway, onto the topic at hand, when I saw you had posted even MORE tutorials for me to read I was like NOOOOOOOOOOO, because that's what I've been doing for about the past 36 hours and my eyes hurt like crazy from staring at the monitor....unfortunately I've already seen all of them except the first one, and I don't know, maybe I'm just stupid or something but I still don't get it :(
The first tutorial though:" An MFC OpenGL Polygon Tessellation Demo", that one had my heart beating a little faster because I thought wow i finally got something here, but then when I ran the application, there was no mouse drawing enabled :( The only way you can do anything in that demo is to load an already existing file (.dat) and then manipulate it using DIALOG CONTROLS. Nothing about the mouse drawing directly onto the viewport or anything unfortunately.....
I've attached a zip file of what I have working so far....all i can do is move these lines across the screen, but I wanna now how to draw them in myself by clicking the mouse!
so once again, if anyone can help me...i'm all ears (and eyes)!
Thanks again,
-Mary
# 3 Re: OPENGL & MFC GURUS (or not)......HELP!
Well, currently I'm at work, but I'll look at it soon in details. Btw, if you only need 2D stuff, then why not use GDI? Is there any particular requirement to use OpenGL? For a simple reference, have a look at this ( http://www.codersource.net/mfc_tutorial_Part3.html)
Ejaz at 2007-11-10 3:52:46 >

# 4 Re: OPENGL & MFC GURUS (or not)......HELP!
Oh man you're at work and here I am shooting off so many questions.....sorry for the inconvenience really :(
You're probably right, maybe my life would be easier if I used GDI graphics instead, but, there are 2 reasons why I can't:
a) Eventually, I'm going to be turning my code into something a lot more complicated...a 3D modeller. This modeller will have 4 viewports; 3 viewports will draw in 2D (one view = xy axis, one view= xz axis, one view=yz axis) and the 4th one will render all of these to show the 3D view. So I hope you see what I'm getting at...in order to for me to get there, I have to get atleast ONE view working...and my 3D rendering will be done in openGL (once I get there), so mixing 3 parts GDI calls with one part OpenGL is probably not a good idea. Do you recommend I mix GDI and OpenGL calls? Especially since GDI doesn't support double buffering...
b) I've spent the last 4-5 days just teaching myself the OpenGL basics...so I'd like to be able to utilize them...if only I could figure out how to pass OpenGL primitives through the mouse!!! I'd be SO SET.
Look forward to hearing from you...
take care,
-Mary
# 5 Re: OPENGL & MFC GURUS (or not)......HELP!
Hello,
I think a good idea is learn very very very good MFC and OGL (also graphics stuffs) before jump to develop 3DSMax (also 2D).
Regards
# 6 Re: OPENGL & MFC GURUS (or not)......HELP!
In addition to what Elementer said, you'll have to concentrate upon 3D maths. Alot of 2D to 3D transformations etc will be involved. For example, as you see that you get x,y from mouse, but in 3D space, there is z also. 0,0 is the top left corner of your view where as in case of 3D, 0,0,0 comes at the center etc.
For starting, have a look at Creating 3D tools with MFC (http://www.gamedev.net/reference/programming/features/3dmfc/)
Ejaz at 2007-11-10 3:55:57 >

# 7 Re: OPENGL & MFC GURUS (or not)......HELP!
Hello boys,
Elementer: Yes I agree, that would definately be ideal if I could spend the time becoming an mfc AND openGL guru, but unfortunately I have limited time and the learning curve is steep (I'm learning these for a graphic's course I'm taking...). trust me, I'm on information overload right now.....my brain is about to crash.
Ejaz: That was a great article you linked; however, even if I have my 4 viewports set up and all the controls are in place.....I'm still stuck on adding that mouse interaction to the viewports..........and it doesn't answer the question of how I get a primitive on the screen (only in the orthographic views) by clicking...
ALL im really wondering is how all the functions are related....so I know where and when to draw when I click the mouse. If I click the mouse, WHICH FUNCTION WILL DRAW MY OPENGL CODE FOR ME? Is it the MFC OnDraw() function, OnPaint ()function? My own RenderScene() (written in the document class) function? Where do I implement the code so it shows up everytime?!?!
I already understand the math behind it all, matrices and matrix transformations are just basic first year university linear algebra.......implementation stuff is easy.....it's getting the openGL code to SHOW UP when I click the mouse that's confusing me......!
Btw ejaz, that article (mashallah) described EXACTLY what I'm trying to do. Just forget about the 3D perpective view however, how do I get the 3 orthographic views working?!?!?!
Some tips would be great...while I continue to read as much as I can...it always helps when someone shares their knowledge..
-Mary
# 8 Re: OPENGL & MFC GURUS (or not)......HELP!
Hello Mary,
(Mary in Italian is a girl name, are you a girl ?), I think you're in the wrong way...
3D graphics stuffs are extreme-hard application, you can't create one only with suggestions, functions takes here and there, and tutorials, someone correct me if I'm wrong...
For 3D math, Ejaz don't mean OGL matrices, linear algebra or similiar things, 3D math is "avanced" math, and there aren't univeristy course that cover that, people at descreet became crazy, they spend 60% of day to solve pages and pages of algorithm and triple integrals about light effects, animation techniques etc..., if you want learn this stuffs, only way is forget loosing time at caf with friends and stay 30 hour at day in your room to study, this is the same thing I'm doing, graphics industry is also my target a day, I don't know what's your one or what are your graphics interests...
All I can do is wish you good luck and link you a MFC q3radiant, this is a good start, but you must be proficient in programming and graphics, also know 3d graphics techniques etc..., here is the link, you can download and study it:
http://www.qeradiant.com/?data=files&files_dir=9
This is the Quake 3 Arena map editor MFC+OGL source code, take a look at this, and appraise yourself...
I'm involved in programming and computer graphics from where I was born, and I think that source isn't a good start for you, all I can recommend is: go little by little, it is the same things that you want to learn univerisisty stuffs when you are at elementary school...
Good luck :) I hope you succeded about...
Best Regards
# 9 Re: OPENGL & MFC GURUS (or not)......HELP!
Hello Elementer (aka flippo)...
My, my, aren't we observant :P Yes, Mary is a "woman's" name and yes, I am a woman.....what do you mean I'm in the wrong way...?
Once again, you are absolutely right on that.....but once again, I am not aiming to become an expert in 3D graphics here....I'm only wanting to do the bare minimum. The 3D modeller that I'm trying to make....will have no textures, no lighting, no shading, no colour, NOTHING. Also, Im not even WANTING to make a perspective or 3D view of my model here.....just forget I even SAID 3D...I am ONLY concerned with 2D right now...ONLY.
All I'm trying to do is draw in 2D orthographic screens, and not FREEHAND draw...just click and a shape shows up. THATS IT. It will just be a very very very VERY simple application that will let me draw with the mouse (ONLY convex shapes...no concave shapes or tesselation needed). ALL i want to do is click the screen, and have a shape show up............it can't be THAT difficult as you are making it sound right now, can it??
I downloaded the q3Radiant source code and you're right......it had my head spinning :P If i was trying to make something like that...then yes it would be like trying to do university level stuff from elementary school.....................but that is overkill for me right now.........i want to keep things as simple as possible.....and q3Radiant has TOO MUCH information (that i could do without at the moment).
In the summer time, when I have more time...I will definately look more deeper into these subjects and study them for, as you say, "30 hours per day", but right now, I'm just trying to get a very very simple application started.....and im stuck on the MOUSE part.
So I'm back to square one......im hoping some tips will go a long way in getting me started......thanks for your time guys..
btw, I came across a GLUT openGL utility that eases windowing basics such as dealing with mouse input, considering that im just keeping things simple, do any of you recommend i use that?
-Mary
# 10 Re: OPENGL & MFC GURUS (or not)......HELP!
Hello,
I'm happy to see a girl in graphics programming, you're the first I see :)
Ok, I undestand ;)
GLUT is easier than MFC+OGL, the Mouse function that GLUT provide, give you the correct mouse (x,y) screen position, but I suggest you to use MFC for controls, like colors, line width etc... you want to use with your first polygons, however, you first step can be a simple green polygon, so GLUT is good for this.
A hint:
create a vertex structure, and when you click at (x,y), create a new vertex and push it to a vertex list. During main loop, draw lines between all vertices...
If you want see the current line rendering in realtime, you can use a simple temporary values (even a temp vertex structure). During mouse movements, render it from pervious point (1st click) to current (x,y), and after 2nd mouse click, set it and push the line into verex list, repeat the step for next line.
If you want draw a rect, it's the same, use 2 vertex, it's up to you decide if rect start must be upper-left corner or lower-left...
This can be a good start...
Bye ;)
