Strange Error...

Started by
12 comments, last by Spunkmeyer 18 years, 7 months ago
 
void topgl::drawbox(int x,int y,int width, int height,float r,float g,float b,float a){
    glColor4f(r,g,b,a);
    glPushMatrix();
    glLoadIdentity();
    if(a < 1.0){
        glEnable(GL_BLEND);
    }
    glTranslated(x,y,0);
    glBegin(GL_LINE_LOOP);
    glVertex2i(width,height);
    glVertex2i(width,0);
    glVertex2i(0,0);   
    glVertex2i(0,height);
 
    glEnd(); 
    if(a < 1.0){
        glDisable(GL_BLEND);
    }    
    glPopMatrix(); 
}

So far for the Code.But strangely, that's the result: strange...
What do you think??
Advertisement
i cant see the picture you were trying to show...
This world is ruled by big furry CATS!! :)Meow! :)
I don't understand why you can't see the picture.
But in ASCII-ART it's like this:
----- |  |-----And i wanted:-----|   |-----


hm...?
May be, you are asking about pixel-perfect texturing and drawing... may be...
So, this topics will help you.

http://www.gamedev.net/community/forums/topic.asp?topic_id=343952
http://www.gamedev.net/community/forums/topic.asp?topic_id=343825
He's talking about pixel perfect line drawing. I see the same problem in my own program. Let's say you do something like:
glTranslated(x,y,0);glBegin(GL_LINE_LOOP);    glVertex2i(0,0);    glVertex2i(10,0);    glVertex2i(10,10);       glVertex2i(0,10);glEnd();

What you should get is a perfectly drawn box using lines. However, depending on what 'x' and 'y' are, the 4 lines can 'jitter' a little, sometimes not lining up quite right, sometimes missing a pixel at a corner, etc. In ASCII art...
// What you want...----------|        ||        ||        |----------// What you can get ...---------- |       | |       | |       |----------// or ---------|        ||        ||        |----------

You can tweak the x and y values to get it to line up just right on your machine, but NVidia and ATI cards have different 'fudge factors' required to get them to line up perfectly. I haven't found a good solution for this yet.
I can fix the Problem, when I add 1 to some coordinates. But on other Grapic-Cards it may look stupid again and its not mathematically correct.

Setting the interpolation of textures doesn't do it.

So, have I to check the vendor of the graphic-board and apply the specific variables? That would be ... dirty!

I wanted a clean box, why is it so complicated... :-(
Quote:From OpenGL.org's Transformations FAQ
If exact pixelization is required, you might want to put a small translation in the ModelView matrix, as shown below:
glMatrixMode (GL_MODELVIEW);glLoadIdentity ();glTranslatef (0.375, 0.375, 0.);


I think that should do what you want.
Unfortunately, I've tried that with no success. I believe it works to get pixel-perfect texturing, but it does not solve the issue with GL_LINES not lining up properly.
Could you not use a quad instead?
Perhaps... but I would then need repeated switches between glPolygonMode(GL_LINE/GL_FILL). I my case, I'm using lines and textured quads to draw my GUI. It would be cumbersome to draw all the textured quads, and then all the lined-quads. Plus, not all line drawing I'm doing can be accomplished using quads.

It's disappointing that this difference exists between OGL implementations, but I can't say I'm surprised. I eventually may switch over to using textured quads for everything, but I can live with the not-so-perfect lines for now.

This topic is closed to new replies.

Advertisement