Jump to content
  • Advertisement
Sign in to follow this  
Xiachunyi

Custom Cursor in Opengl

This topic is 4807 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have been sifting through the internet and the forum's temporary search for a way to render a custom cursor in Opengl. All that I have found are ones linked to DirectX so I am at a stopping point for now. Will anyone kindly point me or explain to me how to create a custom rendered cursor in Opengl? I tried making my own but due to z-distance and most likely the sources of my data, the cursor shows up quite offset from the Window's one.
    glPushMatrix();
	    glTranslated(sPoint.x*, g_rRect.bottom-sPoint.y*, -4.0f);
	    xia_PersonalDrawParticle(0.01, 0.01);
	glPopMatrix();
sPoint is the cursor position derived from the Win32 function of "GetCursorPos(&sPoint);". g_rRect is the window dimensions derived from the Win32 function of "GetClientRect(hwnd, &g_rRect);". One other question. Instead of using GetClientRec, would it be better to do the following to obtain the needed dimension? int viewportCoords[4] = {0}; glGetIntegerv(GL_VIEWPORT, viewportCoords); viewportCoords[3] <-Use this in place of "g_rRect.bottom" Thank you.

Share this post


Link to post
Share on other sites
Advertisement
I appologise because of the lateness, I may make a few mistakes...

gluUnProject will map the screen coordates to OpenGL Coordnates.

You'd use glGet(), to obtain the screen coordnates, the modelview, projection and vewport. Remember, glGet requires you to already have the memory avalible, you don't pass a pointer, you need to pass an array.


IIRC, and it's hazy, you'll also need to switch the Y coordnates, where winY = MaxY - currentY, because Windows maps the Y coordnates different than OpenGL does.

When you're done, a simple translation with the returned objX, objY, objZ will place your cursor where it needs to be.

Share this post


Link to post
Share on other sites
Hmm forget trying to draw the cursor in perspective mode. just use glOrtho.

Because you usually want the cursor on top of everything, you can disable z testing when you draw the cursor. Also, because you want to draw the cursor *last*, there is no need to restore the perspective matrix afterwards (You will be resetting it anyway next frame, right?)

Just draw a textured quad (or anything else you want) at the location of the pointer.

Mark

Share this post


Link to post
Share on other sites
Quote:
Original post by Xiachunyi
Thank you eveyone for helping me. I never thought of utilizing Ortho mode before since I have never used it.
Just remember to offset your cursor so that the 'hotspot' lands on the correct pixel.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!