#### Archived

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

# Technique for moving texture at mouse move coordinates

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

## 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 on other sites
glTranslatef(mouseX, mouseY, 0);

Enigma

##### Share on other sites
I don''t see how that can be done. All I can put in translate are low numbers. Or else the image is way off the screen.

##### Share on other sites
use an ortho projection which has a size which matches your window size (or full screen if in fullscreen mode), then your mouse coords will match

##### Share on other sites
Like this:
glMatrixMode(GL_PROJECTION);
glOrtho(0, this->W, this->H, 0, 0, 0);

glMatrixMode(GL_MODELVIEW);

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);
gluPerspective(100, (GLfloat)892/(GLfloat)672, .1f, 100);

Enigma

##### 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 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 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 on other sites
That worked, although now it is way too small. It is about 50x50 now when it should be 512x512.

1. 1
Rutin
52
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633412
• Total Posts
3011729
• ### Who's Online (See full list)

There are no registered users currently online

×