Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Technique for moving texture at mouse move coordinates

This topic is 5215 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

How do I draw a texture at the mouse move coordinates. I know I may need to use glOrtho but I do not see how I can plug the mouse coordinates into it and have the texture drawn at the cursor.

Share this post


Link to post
Share on other sites
Advertisement
Like this:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, this->W, this->H, 0, 0, 0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(mouseX, mouseY, 0);

It is a tiny little dot in the back of the window. Something is wrong. Here is the initialization code too:

glViewport(0,0, 892, 672);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(100, (GLfloat)892/(GLfloat)672, .1f, 100);

Share this post


Link to post
Share on other sites
I don''t know. Here is the drawing code:
glBegin(GL_QUADS);
glTexCoord2f (0.0f,0.0f); /* lower left corner of image */glVertex3f (-1.0f, -1.0f, 0);
glTexCoord2f (1.0f, 0.0f); /* lower right corner of image */glVertex3f (1.0f, -1.0f, 0);
glTexCoord2f (1.0f, 1.0f); /* upper right corner of image */glVertex3f (1.0f, 1.0f, 0);
glTexCoord2f (0.0f, 1.0f); /* upper left corner of image */glVertex3f (-1.0f, 1.0f, 0);
glEnd ();
SwapBuffers(this->DrawDC);

Share this post


Link to post
Share on other sites
the textures size is 512x512. I put the size of the image W and H in for the x and y of the Vertex for each corner. It draws the image over twice the size that it really is. How can I fix that?
glBegin(GL_QUADS);
glTexCoord2f (0.0f,0.0f); /* lower left corner of image */glVertex3f (-abmp.W, -abmp.H, 0);
glTexCoord2f (1.0f, 0.0f); /* lower right corner of image */glVertex3f (abmp.W, -abmp.H, 0);
glTexCoord2f (1.0f, 1.0f); /* upper right corner of image */glVertex3f (abmp.W, abmp.H, 0);
glTexCoord2f (0.0f, 1.0f); /* upper left corner of image */glVertex3f (-abmp.W, abmp.H, 0);
glEnd ();
SwapBuffers(this->DrawDC);

Share this post


Link to post
Share on other sites
You need to make your quad bigger. Setting your orthographic projection to the size of the screen means each unit is one pixel, so your quad is 2 pixels by 2 pixels! Try changing it to:
glBegin(GL_QUADS);
glTexCoord2f (0.0f,0.0f); /* lower left corner of image */glVertex3f (-32.0f, -32.0f, 0);
glTexCoord2f (1.0f, 0.0f); /* lower right corner of image */glVertex3f (32.0f, -32.0f, 0);
glTexCoord2f (1.0f, 1.0f); /* upper right corner of image */glVertex3f (32.0f, 32.0f, 0);
glTexCoord2f (0.0f, 1.0f); /* upper left corner of image */glVertex3f (-32.0f, 32.0f, 0);
glEnd ();


This will centre the quad at the position of the cursor. To place the quad such that the top left hand corner is in the position of the cursor, either add a glTranslatef(32, 32, 0) before it or change all the -32.0f''s to 0.0f and the 32.0f''s to 64.0f''s. Adjust values for effect.

Enigma

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!