#define _STDCALL_SUPPORTED //Required for
#define _M_IX86 //glut32 and mingw
#include <gl/glut.h>
void Reshape(int width, int height)
{
if (height == 0)
height = 1;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 800, 600, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glColor3f(0, 0, 0);
glBegin(GL_POINTS);
glVertex2i(0,0);
glVertex2i(0,600);
glVertex2i(800,600);
glVertex2i(800,0);
glEnd();
glFlush();
}
int main (int argc, char* argv[])
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800, 600);
glutCreateWindow("OpenGL");
glutReshapeFunc(Reshape);
glutDisplayFunc(Display);
glClearColor(1.0, 1.0, 1.0, 1.0);
glutMainLoop();
return(0);
}
So this should show single pixels in the four corners if I understand correctly. However, it doesn't show anything. I can make the top-left pixel show up by moving the vertex down one pixel. If I draw using GL_QUADS, the square is a pixel smaller than I expect. For example, a square drawn from (50,50)x(55,55) appears at (50,50)x(54,54), but that could be WAI. Something that's really odd is when I draw using GL_LINE_LOOP. I get a square that's missing its top-right corner and is a pixel too high.
I'm using the CodeBlocks IDE, which uses the MinGW compiler.
I realize 2D as simple as this can be a sore subject, so I'll write a nice guide for my UI system once I figure this out and everything is rendering pretty-like.
~Walking_Target
Maybe I'm just an Idiot
I've been trying to get my world coordinates to match my screen coordinates to no success. I'm at a loss why I can't draw pixel for pixel like I would in MSPaint, etc.
--Quick and dirty overview of the code
ehh, maybe increase the point size to glPointSize(10); Maybe the glFlush isn't needed? Maybe the last parameter of glClearColor should be 0. I don't know otherwise, looks like the background is white and the dots should be there in black.
hmmm...have you given:
glOrtho(0, 800, 600, 0, -1, 1); a go. Then even:
gluOrtho2D(0, 800, 600, 0);
And then even something a little more conventional:
glOrtho(0, 800, 0, 600, -1, 1);
or
gluOrtho2D(0, 800, 0, 600);
If none of those make a difference, then....Maybe I'm just an idiot too.
glOrtho(0, 800, 600, 0, -1, 1); a go. Then even:
gluOrtho2D(0, 800, 600, 0);
And then even something a little more conventional:
glOrtho(0, 800, 0, 600, -1, 1);
or
gluOrtho2D(0, 800, 0, 600);
If none of those make a difference, then....Maybe I'm just an idiot too.
Quote:Original post by steven katicYea I've given all of those changes a shot. It is partially fixed by shifting the pixels' vertices by adding to it a little bit. The problem however is that this is not really versatile. If the user changes the window dimensions then it's messed up again.
hmmm...have you given:
glOrtho(0, 800, 600, 0, -1, 1); a go. Then even:
gluOrtho2D(0, 800, 600, 0);
And then even something a little more conventional:
glOrtho(0, 800, 0, 600, -1, 1);
or
gluOrtho2D(0, 800, 0, 600);
If none of those make a difference, then....Maybe I'm just an idiot too.
I think that the problem is actually in mapping the pixels in the world coordinates to the physical pixels.
AFAIK, that's an issue of the rasterizer implementation. The only solution I know is what V-man suggests: add 0.375 to the vertex positions. If the the user resizes the window you should resize your ortho projection matrix as well, since without doing so you'd most certainly NOT get a 1:1 world coord to pixel relation.
Quote:Original post by Walking_Target
I've been trying to get my world coordinates to match my screen coordinates to no success. I'm at a loss why I can't draw pixel for pixel like I would
glVertex2i(0,600);
Shouldn't it be 0,599? You are drawing out of screen.
or glVertex2i(0,600-0.375); ?
wish I could get a user rating of 0. it's a nice round number(if it is a number).How baaaad do I have to be.
wish I could get a user rating of 0. it's a nice round number(if it is a number).How baaaad do I have to be.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement