Sign in to follow this  
el capitan

OpenGL In world mouse cursor.

Recommended Posts

Hello, I'm new to programming and I'm trying to implement little Advance Wars type of game in OpenGL. I have a working heightmap sized 256x256 where the units are and I have enabled mouse picking via glRenderPixels and I can already move the units in the world space via pathfinding and mouse. However, I have major problem. I do not know the method to render mouse cursor onto the heightmap. I assume this could be done via projection like shadows, but wouldn't the cursor texture get skewed? I was guessing projections since it sounds easiest. So, Are there any ways to render the mouse cursor without using the coordinates of the terrain, and simply magically projecting it on it? I have this last resort where the mouse cursor would be rendered on the terrain via the terrain coords, but this would require little storing the terrain in memory, which is bad since i use vbos. I wonder how this is done in commercial games such as Command & Conquer Generals and Warcraft3? I checked the faq and this was in there. I'd appreciate any pointers and help. Thanks.

Share this post


Link to post
Share on other sites
This texture splatting is way over my head, but I will try to investigate further into it. Any other ideas? There had to some way people did it before vertex shaders because I'm sure some games had it before shader times.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I'm really just beginning 3D Graphics coding myself, but aren't decals the way to go for you here?

A texture 'hovering' over the Terrain?

Share this post


Link to post
Share on other sites
I would suggest using that same picking code to find the point on the terrain that the cursor is on, and then render a cursor as a textured quad (probably with an alpha channel and blending enabled, to make it look nice), just above the terrain.
I am sure there are nicer looking ways of doing this, but this is simple.

Share this post


Link to post
Share on other sites
or simply keep the cursor 2D (or with a 3d model) but at 2D depth...

the only game that used a 3d cursor that I know of is Black & White....

just project a line from the cursor to the ground/units... or use opengl's selection / picking function... <-- google. :D

cheers, mate!

Share this post


Link to post
Share on other sites
I figured it out and ended up drawing a quad hovering on terrain. Unfortunately this doesn't work well on very steep surfaces but its a start.

Share this post


Link to post
Share on other sites
Quote:
Original post by el capitan
I figured it out and ended up drawing a quad hovering on terrain. Unfortunately this doesn't work well on very steep surfaces but its a start.


You have to take the slope into account, and angle your quad for the slope.
Maybe projection would be simpler [smile]

Share this post


Link to post
Share on other sites
When you say 'cursor' are you meaning the mark that appears on the ground when you click to send a unit there? If so then I think the effect you are looking for is done by projecting a texture with alpha onto the terrain quads.
If you haven't done any texture projection before, read this article slowly and carefully.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this