   GL coordinates
  I'm trying to match OpenGL coordinates to SDL coordinates since I'm used to SDL coordinates (where the origin is at the top left corner of the window). I would also like to have my OpenGL coordinates directly map to screen/pixel coordinates, so I have written this (following the advice here):glViewport(0, 0, (int)window_w, (int)window_h);    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    glOrtho(0, window_w, 0, window_h, 1, 200);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();In this case, window_w is 640 and window_h is 480. This code doesn't do what I want, though. For example, I'd like this snippet to draw a line from the top left corner of the screen to 5 pixels down and to the right (south east). Instead, the origin is at the centre of the screen and the line goes outside the screen.Cheers.   
  my engine 2d mode initialization:void Start2D(int sizex, int sizey){glViewport(0,0,sizex,sizey);glDisable (GL_CULL_FACE);glDisable ( GL_DEPTH_TEST ); glMatrixMode( GL_PROJECTION );glLoadIdentity();glOrtho(0, sizex, sizey,0,-1,1); glTranslatef(0.375f,0.375f,0.0f);glMatrixMode( GL_MODELVIEW );glLoadIdentity();}opengl use as (0,0) left botom corner of viewport. if you want use left TOP corner as (0,0) then you need use "glOrtho(0, sizex, sizey,0,-1,1);" not "glOrtho(0, sizex, 0,sizey,-1,1);"."glTranslatef(0.375f,0.375f,0.0f);" used for right processed subpixel coordinatessorry for bad english.   ;  Hey HolyDel.Cheers for the correction. I added it in but it's still drawing the line weirdly:void GL_Tools::Init_GL(double window_w, double window_h){    glClearColor(0.0,0.0,0.0,1.0);// background colourglClearDepth(1.0f);// depth bufferglEnable(GL_DEPTH_TEST);// (z-buffer) depth testingglDepthFunc(GL_LEQUAL);// type of depth testingglShadeModel(GL_SMOOTH);// enables smooth shadingglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);    glEnable(GL_TEXTURE_2D);   // enables textures    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);    /* This will make GL co-ords map to screen pixel co-ords. */    glViewport(0, 0, (int)window_w, (int)window_h);    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    glOrtho(0, window_w, window_h, 0, 1, 2);    glTranslated(0.375, 0.375, 0);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();    // Clear the screen of old crap.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Reset the view    glLoadIdentity();}glColor3d(1, 0, 0);    glBegin(GL_LINES);    glVertex3d(0, 0, 0);    glVertex3d(5, 5, 0);    glEnd();;  Hey, Mybowlcut.glOrtho(0, window_w, window_h, 0, -1, 1);if you use 1 as near plane and 2 as far plane, then z coordinates in you gl primitives must be in this range (1..2).also, may use:glVertex2f(x,y); or glVertex2i(x,y);for drawing gl primitives.   ;  There are two things that suggests that the matrix setup you show is not in use. First, the depth range of your setup is from Z=-1 to Z=-2, and you draw at Z=0, but still see something. The origin is obviously at the center, but you set it in the upper left corner.The default setup will give you exactly what you get, which suggests that you either clear the matrices just before drawing, clearing the previous matrices; or set the matrices when you don't have a rendering context, and so the calls don't have any effect.   ;Quote:Original post by HolyDelHey, Mybowlcut.glOrtho(0, window_w, window_h, 0, -1, 1);if you use 1 as near plane and 2 as far plane, then z coordinates in you gl primitives must be in this range (1..2).also, may use:glVertex2f(x,y); or glVertex2i(x,y);for drawing gl primitives.Thanks - I didn't know that. :)Quote:Original post by Brother BobThere are two things that suggests that the matrix setup you show is not in use. First, the depth range of your setup is from Z=-1 to Z=-2, and you draw at Z=0, but still see something. The origin is obviously at the center, but you set it in the upper left corner.The default setup will give you exactly what you get, which suggests that you either clear the matrices just before drawing, clearing the previous matrices; or set the matrices when you don't have a rendering context, and so the calls don't have any effect.Hey again Bob haha.You're right! It was the latter; I had created a SDL_Window class that created the window and was calling Init_GL before I had created the SDL_Window.I have fixed this, but now nothing shows up.Init_GL looks like this:void GL_Tools::Init_GL(double window_w, double window_h){    glClearColor(0.0,0.0,0.0,1.0);// background colourglClearDepth(1.0f);// depth bufferglEnable(GL_DEPTH_TEST);// (z-buffer) depth testingglDepthFunc(GL_LEQUAL);// type of depth testingglShadeModel(GL_SMOOTH);// enables smooth shadingglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);    glEnable(GL_TEXTURE_2D);   // enables textures    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);    /* This will make GL co-ords map to screen pixel co-ords. */    glViewport(0, 0, (int)window_w, (int)window_h);    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    glOrtho(0, window_w, window_h, 0, -1, 1);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();    // Clear the screen of old crap.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Reset the view    glLoadIdentity();   glTranslated(0.375, 0.375, 0);}SDL_Window:SDL_Window::SDL_Window(unsigned short screen_width, unsigned short screen_height,unsigned short screen_bpp, const std::string& screen_caption): screen_width(screen_width), screen_height(screen_height), screen(NULL), screen_bpp(screen_bpp), screen_caption(screen_caption){screen = SDL_SetVideoMode(screen_width, screen_height, screen_bpp, SDL_OPENGL);if(screen == NULL){throw LRE_Exception(std::string("Error: SDL_SetVideoMode failed:\nSDL: " +std::string(SDL_GetError())));}SDL_WM_SetCaption(screen_caption.c_str(), NULL);// Enable key repeatingif(SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) == -1){throw LRE_Exception(std::string("Error: SDL_EnableKeyRepeat failed.\nSDL: ") +std::string(SDL_GetError()));}LOG("SDL_Window initialised.");}SDL_Window::~SDL_Window(){LOG("SDL_Window cleaned up.");}void SDL_Window::Render(){    SDL_GL_SwapBuffers();    // Clear the screen of old crap.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Reset the view    glLoadIdentity();}Trying to draw something:glColor3d(1, 0, 0);    glBegin(GL_LINES);    glVertex3d(0, 0, 0);    glVertex3d(50, 50, 0);    glEnd();It just shows up as a black screen.Cheers for your help guys!   ;  I hope this is helpful.When I was placing text in an openGL window, even though the screen is 800x600 (my window size) the dimension within is only +2.0 to -2.0 from left to right.  Try making your lines like .05 to -0.05, see what shows up, where.  I'm still trying to figure out where and how it scales the screen, but each template I use to try to learn on, the width of the scaled screen has always been different (-1.0 to +1.0 or other odd stuff I haven't nailed down yet.)   ;  Hey. Thanks for the reply.I tried what you suggested but it's still not showing up. I also tried drawing other things like triangles with no luck...   ;  Remember that after every call to glLoadIdentity you'll need to call glTranslated again.edit: also. SDL_GL_SetAttribute needs to be called before GL_SetVideoMode (can't see if you're calling Init_GL before or after creating the window, but it should be after).   ;  You mean I need to call glTranslate again for each object I want to draw? I know that and have got my code doing it.As for SDL_GL_SetAttribute being called before SDL_SetVideoMode, I did it (called Init_GL before creating the SDL_Window object - which calls SDL_SetVideoMode) but it's still black. :(I've stripped my code down to a compilable example, but still... I see nuzzing!int main(int argc, char* args[]){try{if(SDL_Init(SDL_INIT_EVERYTHING) == -1){throw LRE_Exception(SDL_GetError());}   int window_w = 640, window_h = 480;glClearColor(0.0,0.0,0.0,1.0);// background colour    glClearDepth(1.0f);// depth buffer    glEnable(GL_DEPTH_TEST);// (z-buffer) depth testing    glDepthFunc(GL_LEQUAL);// type of depth testing    glShadeModel(GL_SMOOTH);// enables smooth shading    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);   glEnable(GL_TEXTURE_2D);   // enables textures   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);   /* This will make GL co-ords map to screen pixel co-ords. */   glViewport(0, 0, window_w, window_h);   glMatrixMode(GL_PROJECTION);   glLoadIdentity();   // Want origin at top-left.   glOrtho(0, window_w, window_h, 0, -1, 1);  glMatrixMode(GL_MODELVIEW);   glLoadIdentity();   // Clear the screen of old crap.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   // Reset the view   glLoadIdentity();   // Account for line/point thingy.   glTranslated(0.375, 0.375, 0);   SDL_Surface* screen = SDL_SetVideoMode(window_w, window_h, 24, SDL_OPENGL);    if(screen == NULL)    {    return 0;    }    //SDL_WM_SetCaption("wwweeeee", NULL);   glBegin(GL_TRIANGLES);   glVertex2d(-5, 0);   glVertex2d(5, 5);   glVertex2d(-5, 5);   glEnd();   SDL_GL_SwapBuffers();   Sleep(3000);}catch(const std::exception& r){std::cout << "Exception caught: " << r.what() << std::endl;}    SDL_Quit();    return 0;}