Hello,
I am coding what I hope will become a multi platform, multi API GUI library, and I am writting the OpenGL portion of it.
To make the story short I will just say that I need to implement some basic drawing functions such as DrawPixel, DrawLine, DrawRect and DrawFilledRect, I started implementing these for SDL, and sure enought when I do a DrawPixel(x,y) with SDL the pixel shows up at x,y, when I do DrawLine(x1,y1,x2,y2), the line goes from x1,y1 to x2,y2 inclusive, everything is fine.
But now that I am implementing the same stuff on OGL, which is supposed to be easier, it isn't! when I say DrawPixel(10,10) a pixel gets drawn at 10,10, but when I say DrawLine(10,0,10,200) for example, the line gets drawn at (9,0,9,200), if I try to draw a pixel at 0,0 it doesnt show, but if I try it at 1,1 it shows and its in the spot it should be! this is driving me crazy.
Now, I am getting into Ortho mode with this code:
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,640,480,0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_BLEND);
I tried changing glOrtho(0,640,480,0, 0, 1) to
glOrtho(0,639,479,0, 0, 1),glOrtho(-1,639,479,0, 0, 1) and
glOrtho(-1,639,479,-1, 0, 1), no luck.
Then line and pixel functions (GUIColor is a union which holds the ARGB values for a color):
void DrawPixel(Sint16 x, Sint16 y,GUIColor color)
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glColor4ub(color.color.R,
color.color.G,
color.color.B,
color.color.A);
glBegin(GL_POINTS);
{
glVertex2i(x, y);
};
glEnd();
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
};
void DrawLine(Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2,GUIColor color)
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glColor4ub(color.color.R,
color.color.G,
color.color.B,
color.color.A);
glBegin(GL_LINES);
{
glVertex2i(x1,y1);
glVertex2i(x2,y2);
};
glEnd();
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
};
Any Ideas?
[Edited by - Kwizatz on September 21, 2004 8:16:43 PM]