Looking for something equivalent to context.translate(x,y)

Hello everyone,

On similar drawing api’s i have a function which i use to implement camera movement. For instance, on Java2D i can use [1] and javascript i can use [2], they are quite similar (not complete equal, but similar)

But on SDL i had no success on find something similar to this.

I’ve solved my issue by using a second buffer to draw the background buffer and the sprites and then draw that on the screen. But find a solution able to make the 3 research codebases more similar to each other would be nice.

For context, please see the following Cameras and Scenarios (see links, not going to pollute the post.)

SDL version
http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-cpp/Camera.cc?r=360
http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-cpp/Scenario.cc?r=360#65

Java2D version
http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-java/src/yarpg/Camera.java?r=360
http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-java/src/yarpg/Scenario.java?r=360#67

Canvas/Javascript version
http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-js/yarpg-js/Camera.js?r=360
http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-js/yarpg-js/Scenario.js?r=360#53

[1] http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Graphics.html#translate(int,%20int)
[2] https://developer.mozilla.org/en/Canvas_tutorial/Transformations#Translating

Thanks in advance.

SDL doesn’t define a drawing API like those you mention. It is entirely
raster-based and low-level. You get access to the raw pixel data and
there’s a blitting routine. Other APIs may use SDL to provide an interface
to graphics primitives (SDL_gfx, SPriG), vector graphics (similar to
Canvas), or matrix transformations on pixel data (similar to OpenGL). You
could even implement the Java2D API on top of SDL. The graphic primitives
need to be aware of this global transformation state, and that is just not
within the scope of SDL proper.

If you’re not interested in doing it yourself, you might have a look at
cairo (http://cairographics.org/). I did once try it out with SDL and it
was pretty neat. If you need better performance, you would want to use
OpenGL in the end (and cairo does have an OpenGL backend that can be set up
with SDL).

Jonny DOn Mon, Mar 26, 2012 at 7:46 PM, sombriks wrote:

**
Hello everyone,

On similar drawing api’s i have a function which i use to implement camera
movement. For instance, on Java2D i can use [1] and javascript i can use
[2], they are quite similar (not complete equal, but similar)

But on SDL i had no success on find something similar to this.

I’ve solved my issue by using a second buffer to draw the background
buffer and the sprites and then draw that on the screen. But find a
solution able to make the 3 research codebases more similar to each other
would be nice.

For context, please see the following Cameras and Scenarios (see links,
not going to pollute the post.)

SDL version

http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-cpp/Camera.cc?r=360

http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-cpp/Scenario.cc?r=360#65

Java2D version

http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-java/src/yarpg/Camera.java?r=360

http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-java/src/yarpg/Scenario.java?r=360#67

Canvas/Javascript version

http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-js/yarpg-js/Camera.js?r=360

http://code.google.com/p/sombriks-hq/source/browse/trunk/yarpg-js/yarpg-js/Scenario.js?r=360#53

[1]
http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Graphics.html#translate(int,%20int)
[2]
https://developer.mozilla.org/en/Canvas_tutorial/Transformations#Translating

Thanks in advance.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi Jonny D, thank you for the quite instructive answer!

Nice to know that SDL gives me more control, since i already solved the issue and have the desired result i’ll just keep plain SDL and no aditional dependencies for drawing.