🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Tutorial 2 and 32

Started by
4 comments, last by Redien 17 years, 9 months ago
I have been tying to learn how to select objects from tutorial 32. What I did is load tutorial 2 and edit out the triangle. What I want to be able todo is left click and select the square. So I load tutorial 32 and copy over the Selection() function. I put the selection() down where WM_LMBUTTONDOWN is just like in tutorial 32. First thing I did is edit the selection() function so it just reads glBegin() (draw quad here) glEnd() real basic so I can test it when the left mouse button is pressed. Now, when I run it, compiles error free and runs, I get my square right on the screen just fine, but when I left click nothing happens. What I did next is comment out the selection() function and just added it in the DrawScene() function, and it draws it just fine! I dont understand, it is like the mouse isnt even being used. Any idea?
Advertisement
Ok, lets see if I understand your problem.
You copied the selection() function from lesson 32 and removed everything in it except for the part that draws the square?
And you're also drawing the square in your main loop?

If that's what you have, what are you expecting it to do?
If you remove the GL calls that enables picking, then OGL have no way of knowing that you want it to return a picked object, and therefore OGL just renders an exact copy of the square ontop of the first square.

I don't really understand what you have/haven't changed in the code.
Some source would help to clear things up a litte. :)

[Edited by - Redien on September 26, 2006 6:23:34 AM]
What I want to do is try and use tutorial 2 and practice learning to pick objects. So I loaded tut32 and read it. I see that all of the picking is done in the selection() function. And then he calls the selction function with WM_LMBUTTONDOWN in winmain(you click the left mouse button and it stores everything as hit). So what I do, is see if I can get my call to WM_LMBUTTONDOWN to work. So I used his selection() function and just erase everything out and make it draw a square by translating it above the one in tutorial 2 instead of what it is meant to do. So, then I compile it and the normal tutorial 2 square shows up fine. Well, when I click my mouse button, I am suppose to get a new translated square right above it! BUT!! I dont't, I am lost and have no idea why. It is like the winmain call to the mouse isn't even there.
:) The WM_LBUTTONDOWN message is only sent once.
What you're doing is that you draw the square one time just when you click the mouse button.
Then when you clear the color buffer, the square is erased.

So what you'll have to do is create a variable to hold the current state of the mouse button.
( i.e. when you get a WM_LBUTTONDOWN message, set the variable to true and when you get WM_LBUTTONUP, set it to false )
That way you can just check the value of the variable and draw the square right after you draw the first one, if the variable is true. :)

[Edited by - Redien on September 26, 2006 12:30:58 PM]
I thought his tutorial 32 code already did this for me? If you look at it he adds the selection() function there as well.
The only place in the code where I can find a call to Selection() is where he checks for the WM_LBUTTONDOWN message.

The Draw() function is called from the loop in WinMain().
DrawTargets() is the function that renders all of the objects.
It calls object() for each object, wich draws a quad.

Draw() and Selection() calls DrawTargets().

so if you remove everything from Selection() and just render a quad, then it's only going to get called when you click the mouse.

Try putting Selection() in either the Draw() function, or add it after WinMain() calls Draw() and before it swaps the buffers. :)

This topic is closed to new replies.

Advertisement