# OpenGL glRasterPos, glDrawPixel and discarding images

This topic is 4221 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello people, I need help with solving a problem which can be seen in the image below. I've setup my projection as a 2d projection using
 glViewport(0,0,200,200);

glMatrixMode(GL_PROJECTION);
glOrtho((GLdouble)0,(GLdouble)200,(GLdouble)0,(GLdouble)200,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);


The problem is, if my raster position is less than (0,0) say (-32,0) or (-32,-32), OpenGl does not draw the image. So I get jaggered empty tile spaces around the left and bottom edges while drawing my tile layer. Is there a way to make OpenGl perform clipping and partial drawing of images? So that if a tile is 32x32 and the raster position is (-10,0) it will draw the pixels in the tile from x = 20 and not discard (clip) the whole image.
void draw_tile(float x,float y,int width,int height,unsigned char *data,bool alpha)
{
glRasterPos2f(x,y);

if(alpha==true)
{
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL, 0);
glDrawPixels(width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);
}
else
{
glDisable(GL_ALPHA_TEST);
glDrawPixels(width,height,GL_RGB,GL_UNSIGNED_BYTE,data);
}

}


P.S: I know about using textured quads,just want know how to fix this issue. I've tried using GL_SCISSOR_TEST and smaller viewports but that does not fix it. Thanks for all the help, Andrew K.

##### Share on other sites
As you've realized, specifying a raster position outside of the current viewport results in no part of that rasterization getting drawn. However, from the documentation,
Quote:
 To set a valid raster position outside the viewport, first set a valid raster position, then call glBitmap with NULL as the bitmap parameter.

glBitmap( ) says a little more:
Quote:
 To set a valid raster position outside the viewport, first set a valid raster position inside the viewport, then call glBitmap with NULL as the bitmap parameter and with xmove and ymove set to the offsets of the new raster position. This technique is useful when panning an image around the viewport.

So, it seems like call glRasterPos somewhere inside the viewport first, then use the xmove and ymove parameters of glBitmap to move outside of the viewport.

Does that do the trick?
-jouley

##### Share on other sites
Jouley, Thanks a million!!!!

Yep, it does the trick.

I just modified the start of draw_tile
from
  glRasterPos2f(x,y);

to
  if(x < 0.0 || y < 0.0)    {        glRasterPos2i(0,0);        glBitmap(0,0,0,0,x,y,NULL);    }    else        glRasterPos2f(x,y);

This had been giving me problems for a long time.
I appreciate the help.

Onto moving around the iso map:D

1. 1
2. 2
3. 3
4. 4
Rutin
14
5. 5

• 12
• 12
• 9
• 14
• 10
• ### Forum Statistics

• Total Topics
632655
• Total Posts
3007670
• ### Who's Online (See full list)

There are no registered users currently online

×