• Advertisement

Archived

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

Technique for moving texture at mouse move coordinates

This topic is 5128 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
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 this post


Link to post
Share on other sites
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
Dividing by two seems to be the solution. Why doesn''t gluPerspective seem to make any difference?

Share this post


Link to post
Share on other sites
If your texture is 512 by 512 then yes you'll need -256 to 256 because the total width = 256 - -256 = 512. The reason gluPerspective isn't doing anything is because you're overriding it when you do glOrtho.

EDIT: looking at your glOrtho call, you might want to change the last two parameters to -1 and 1. At the moment your frustrum has zero depth and I don't know that OpenGL makes any guarantees that that will work.

Enigma

[edited by - Enigma on February 8, 2004 7:49:45 PM]

Share this post


Link to post
Share on other sites
You say that rotation does not work correctly. What are you trying to do and what is actually happening. Is it rotating on the wrong axis? By the wrong amount? Around the wrong point?

Enigma

Share this post


Link to post
Share on other sites
glRotatef(tick, tick, 0, 0);
tick goes from 360 to 0.
Before I used the Ortho stuff I was able to rotate the image around on any axis and it would look 3D and be perfect. But now when it just clips the image and looks terrible.

Share this post


Link to post
Share on other sites
First of all you might want to look up a reference on glRotatef. The last three parameters define an axis, so to specify using a variable only on x is pointless. You probably mean glRotatef(tick, 1, 0, 0).

The clipping problem is because of your near and far clip planes. I''m afraid I don''t have time to give an explanation right now, try looking at the red book.

Enigma

Share this post


Link to post
Share on other sites

  • Advertisement