Skip to main content
gamedev.net
🔒 Locked

glDrawPixels

Started by -Thork- 1 reply 900+ views
Original Post
-Thork-
-Thork-
Is there any way to make glDrawPixels draw slightly out the left or top sides of the Viewport? I''ll explain what I mean... I''m using OpenGL in Orthographic projection to draw the GUI for a game, and I need to add a cursor. The problem arises when the hot-spot of the cursor is not in the top left of the image. If I had a 32x32 cursor with the hot-spot at 16,16 and the user moves the cursor to the top left of the window (where the cursor image would be drawn from (-16 -> +16, -16 -> +16), then glDrawPixels doesn''t draw the image. It works fine on the right and bottom sides of the window where the other sides of the cursor disappear out the side. Any ideas? Here''s my code:
  
	glMatrixMode(GL_PROJECTION);	// Change to Projection Matrix

	glPushMatrix();					// Save the current Projection Matrix

	glLoadIdentity();				// Clear the current Projection Matrix


	glOrtho(0.0f, (float)wScreenCX, (float)wScreenCY, 0.0f, -1.0f, 1.0f);	// Create Orthographic Projection


	glMatrixMode(GL_MODELVIEW);		// Change to ModelView Matrix

	glPushMatrix();					// Save the current ModelView Matrix

	glLoadIdentity();				// Clear the current ModelView Matrix

	
	// Draw TGA

	glPixelZoom(1.0f, -1.0f);	// Flip images (they appear upside-down otherwise)

	glRasterPos3f((float)wX - (float)wHotX, (float)wY - (float)wHotY, 0.0f);	// Set drawing position

	glDrawPixels(wWidth, wHeight, GL_RGBA, GL_UNSIGNED_BYTE, tgaImage);

	glPopMatrix();					// Restore ModelView Matrix

	glMatrixMode(GL_PROJECTION);	// Change to Projection Matrix

	glPopMatrix();					// Restore Projection Matrix

	glMatrixMode(GL_MODELVIEW);		// Change to ModelView Matrix

  
The tgaImage variable defines the RGBA data of the cursor taken from my CTGAImage class, the wX and wY variables specify the cursor position, while the wHotX and wHotY variables define the hot-spot of the cursor (16, 16 in the above example). The wWidth and wHeight are the dimensions of the cursor and wScreenCX and wScreenCY specify the dimensions of the screen. I tried changing glOrtho to -16.0f, 640.0f, 480.0f, -16.0f, but that didn''t work either, as you would expect.
Basiror
Basiror
well the piece of code you show us here is a cheap implementation of a cursor

actually it is more complex

you know the screen width and height
in order to draw cursor correct you have to get the cursor position from the system

when you use a 32*32 pixels large cursor you have to setup the collision detection so that you have a 16 units large border outside the screen
and to draw the cursor you need make the collision so that it can move between 1,1 and screenwidth,screenheight
and then calculate which pixels are visible

an easy solution would be to see whether one pixel would be outside the screen if so
create an image image[wWidth-16][wHeight-16] that contains the pixel from the from [wWidth-16][wHeight-16] to[wWidth][wHeight]
and set your rasterposition to 1,1


that way you align it the border of the window but you still have a visible hotspot another way would be to set the hotspot to 1,1 at the spike of the cursor ....
you should have an idea of how it works now
at least i hope so

http://www.8ung.at/basiror/theironcross.html
-Thork-
-Thork-
That''s wasn''t all the code for my cursor, just the drawing code. I''ve fixed it now anyway, by getting the code to recreate the section of the image that it actually needs to draw, which possibly isn''t the best way of doing it, but it''ll do unless I can figure anything else out.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.