Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 paulg568   Members   -  Reputation: 100

Like
0Likes
Like

Posted 17 January 2012 - 12:15 AM

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.

Sponsor:

#2 the_visualist   Members   -  Reputation: 169

Like
0Likes
Like

Posted 17 January 2012 - 12:35 AM

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

#3 dpadam450   Members   -  Reputation: 946

Like
0Likes
Like

Posted 17 January 2012 - 02:06 AM

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.

#4 paulg568   Members   -  Reputation: 100

Like
0Likes
Like

Posted 17 January 2012 - 04:10 PM

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

#5 paulg568   Members   -  Reputation: 100

Like
0Likes
Like

Posted 17 January 2012 - 04:47 PM

Translating it to a negative spot didn't work. It stopped it at zero.

#6 Brother Bob   Moderators   -  Reputation: 8576

Like
0Likes
Like

Posted 17 January 2012 - 04:47 PM

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.

#7 dpadam450   Members   -  Reputation: 946

Like
0Likes
Like

Posted 17 January 2012 - 05:45 PM

So how do you draw an image partially off the screen?


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.

#8 paulg568   Members   -  Reputation: 100

Like
0Likes
Like

Posted 18 January 2012 - 12:27 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS