Moving image around screen using glDrawPixels

Started by
8 comments, last by aewarnick 20 years, 2 months ago
How do I move an image around on the screen in the location of the mouse as the upper left corner. No need to go into getting mouse movement or coordinates. I just can''t figure out how to draw an image in a certain spot.
*C++*->
Advertisement
First of all you probably shouldn't be using glDrawPixels because it is slow. Instead try using a textured quad and an orthographic projection (google glOrtho). If you don't know about textures then try the NeHe tutorials. Note that each side of a texture must be a power of two* (i.e. 256 by 32 is valid, 65 by 91 isn't). If your image is not a power of two on each side then pad it until it is and modify the texture coordinates to only display the part of the texture that contains your image.

Enigma

*except if you use one of the texture rectangle or non-power-of-two extensions.

EDIT: forgot my *.

[edited by - Enigma on February 7, 2004 11:47:58 AM]
Thanks for clarifying that drawpixels is slow. I thought it was while testing but now I know for sure.
"modify the texture coordinates to only display the part of the texture that contains your image"

How do I do that when all I have to work with is 0.0 to 1.0?

[edited by - aewarnick on February 17, 2004 3:08:47 PM]
*C++*->
If your image only takes up 192 of 256 pixels horizontally, then use texture coordinates 0.0f to 0.75f. Have a look at some of these texturing tutorials.

Enigma
I didn''t find anything I didn''t already know. They didn''t go into using images with erradicate sizes.

What is this about,
"*except if you use one of the texture rectangle or non-power-of-two extensions."?
*C++*->
Nevermind, I found that someone else posted about this same kind of topic. He had a good point, if I pad the image it may take up 3 times as much space.

I guess I could split the image into many many textures but will there be a drawing speed hit because of looping?
*C++*->
i have a question:

isn''t there any ability in opengl to draw something in 2d ? Like overlaying the output buffer. It seems to me that drawing something in 3d which will look like 2d is wasting resources.
switch to ortho mode and draw like it is 2d, the added bonus is that this goes via the hardware 3d route and thus gets better accelration (same way DX does DirectDraw now i belive)
Does looping through an image that is split into many textures slow down speen compared to drawing the whole image with one texture?
*C++*->

This topic is closed to new replies.

Advertisement