SDL coordinate system

Started by
1 comment, last by viperman1271 16 years, 4 months ago
Is there a way to change the SDL coordinates from http://lazyfoo.net/SDL_tutorials/lesson02/sdlcoord.jpg to http://lazyfoo.net/SDL_tutorials/lesson02/cartesian.jpg
Advertisement
The easiest way is to subtract the y coordinate from the screen height every time you want to display graphics. Another, more practical way is to use OpenGL for all of your graphics plotting functions as is outlined in a later tutorial on that same website. OpenGL offers much more hardware graphics acceleration than is available on SDL 1.2.x alone.
The SDL coordinate system is not the only system that doesn't use the standard cartesian coordinate system, thus it may be beneficial (that is if you plan to expand to other engines or do more graphics programming in the future) to adapt to the SDL coordinate system. However, if you are still keen on using the cartesian system I would agree with samuraicrow with one added thing, write a function (or set of functions) that you could use repeatedly to display stuff. For example

SDL_Surface *screen;//This it the surface to draw to

void drawToScreen(int x, int y)
{
int newX, newY;
newX = x;
newY = screen->h - y;
object.draw(newX, newY); //Calling your draw function
}

In an attempt to make the program more memory friendly and reduce the number of function calls, making the function inline may help (depending on your compiler). I hope this helps

This topic is closed to new replies.

Advertisement