Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL Request Sample

Started by shing19861006 Mar 4, 2009 at 3:40 AM 6 replies 800+ views
Original Post
shing19861006
shing19861006
Could you please help me make a simple sample for me? I would like to request a sample is make by Dev C++. The content of sample is: Create 1 red cube and 1 blue cube. Show a messagebox event when i click the red cube Such as MessageBox(NULL, "red cube is clicked", "", MB_OK); And MessageBox(NULL, "blue cube is clicked", "", MB_OK); Thank you for your help.
Brother Bob
Brother Bob
So what part of the program are you having problem with?
shing19861006
shing19861006
No any problem.
Just i don't know how to create a mouse event.
Can you help me make a sample?
Brother Bob
Brother Bob
I will not write a program for you, but I can answer questions and help with specific problems.

Given that you're using MessageBox, I assume Win32 API. So to catch mouse events, process, for example, the WM_LBUTTONDOWN message in your window message handler.
shing19861006
shing19861006
I mean when i click the red cube or blue cube.
Brother Bob
Brother Bob
There are some options then.

  • Check the selection mechanism in OpenGL (see for example NeHe lesson 32) which will give you object names in a specified selection area.

  • Color based selection is also an option, where you render objects into the back buffer and makes the selection based on what color is under the mouse cursor. The fact that you already render the cubes in different colors simplifies this. Basically, render each object in a unique color (without lighting, texturing, fogging, or anything that shades the final color, you just want a pure color for selection). On click, read the color under the cursor and match with your objects. In your case, read the frame buffer, and if the color is red, you selected the red object, and so on.

  • Manual geometric selection. Cast rays into the scene from the viewpoint through the mouse cursor. Intersect the ray with all objects in your scene. Objects that intersect the ray appears under the cursor and are therefore selected.


Personally I recommend first option.
shing19861006
shing19861006
But this lesson is too hard.
I need simple example.
Thanks.
LackOfGrace
LackOfGrace
i dont think anyone have time or want to do a sample for you.
read up on OpenGL picking, preferably on nehe

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.