Jump to content
  • Advertisement
Sign in to follow this  
paulg568

GUI Images don't render if x position is negative.

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

I wrote my own gui image renderer.

I am having an issue with images not rendering if there position is negative even if part of the image is still on screen.

Here is my code:


glEnable(GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glRasterPos2f(xPos, yPos);
glPixelZoom(xScale, yScale);
glDrawPixels(originalWidth, originalHeight, GL_RGBA, GL_UNSIGNED_BYTE, imageData.bits());
glPopMatrix();
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);


Anyone know how to fix this?

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Basically this works without problems, maybe it just doesn't work with your code. The problem might be glRasterPos2f - maybe it just doesn't work with negative coordinates, which would make some kind of sense.

Anyway here is my texture drawing code that also works for negative positions:

// The parameters iLeft, iTop are the position (for example 0,0 or -20, -20 to draw it a bit in the negative area).
// fixedwidth, fixedheight are the texture width and height.
// m_height is the window height.

// ... bind texture etc.

// Draw quad (float format because its simply faster)
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f); glVertex2i(iLeft, m_height-iTop); // Top Left
glTexCoord2f(1.0f, 1.0f); glVertex2i(iLeft+fixedwidth, m_height-iTop); // Top Right
glTexCoord2f(1.0f, 0.0f); glVertex2i(iLeft+fixedwidth, m_height-iTop-fixedheight); // Bottom Right
glTexCoord2f(0.0f, 0.0f); glVertex2i(iLeft, m_height-iTop-fixedheight); // Bottom Left
glEnd();

// ... unbind texture etc.


the_visualist

Share this post


Link to post
Share on other sites
I have never used raster position, and instead use what the other person suggested. Since you are explicitly setting a pixel x and y, it may be realizing that you are writing to a piece of memory that is not there for the image and it is deciding not to draw. Not sure.

from here:
http://msdn.microsoft.com/en-us/library/dd373990%28v=VS.85%29.aspx
"When the raster position coordinates are invalid, drawing commands that are based on the raster position are ignored (that is, they do not result in changes to the OpenGL state)." So clearly you can give it bad input and based on that input the draw doesn't happen.

Share this post


Link to post
Share on other sites
So how do you draw an image partially off the screen? I am going to try what I am about to say and let you know if it works.

If x is negative use glTranslafef to translate it partially offscreen.

In the mean time if someone else has an idea how to draw image partially on screen let me know.
Thanks.

-Paul

Share this post


Link to post
Share on other sites
If the raster position set by glRasterPos is clipped (outside the view volume), it is marked as invalid and any command relying on the raster position is ignored.

If you're specifying your coordinates in window space, then use glWindowPos instead of glRasterPos. The benefit is that you don't have to setup the modelview and the projection matrices for coordinate-to-pixel mappings, and the raster position is never invalid.

If you're specifying it in any other coordinate system, I suggest you project the point manually to determine what the screen space coordinates would be, and then set the raster position with glWindowPos.

Share this post


Link to post
Share on other sites
So how do you draw an image partially off the screen?[/quote]

Use glOrhtho() with the window coordinates of your screen size. then call glVertex2f() where you want the image to be. If it is offscreen that is fine and it will render whatever part is on the screen. This is because clipping happens. When using glRasterPos, you are directly writing pixels and pixel location -1,-1 is not a part of memory for your screen, only 0,0 to width,height are valid pixels to write. glVertex2f() takes care and clips so that it only tries to write pixels that are in the image that will map in 0,0 to width,height and therefore never writes -1,-1 etc pixels.

Share this post


Link to post
Share on other sites
Thanks for the replies.

Using glWindowPos2i did the trick.

I tried glVertex2f and the images showed up in the bottom left regardless of position. I am new to opengl and am going to make a guess as to why this didn't work. Don't you generally need veretex positions for polygons, not raster images or pixmaps?

Lastly, how do I mark a post as solved? I have made two posts and in both cases I need to mark the posts solved/complete/closed.

Thanks for everyones' help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!