Jump to content
  • Advertisement
Sign in to follow this  
Andrew Kabakwu

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.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

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



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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!