SFML community forums
Help => Graphics => Topic started by: SuperV1234 on November 27, 2012, 11:08:34 pm
-
Sorry if this has been asked before, but is there a way to create a "3D camera" in SFML?
I want to look at a RenderTexture from a different perspective. And rotate the camera around it, in order to give a pseudo-3D effect to my game.
Is there any user-made code that does this?
-
SFML is a 2D library, thus you won't find any 3D stuff... ;)
If you want 3D then use your own OpenGL code.
-
I've heard that you can also use some 3D graphic engines such as irrlicht, I've only used raw OpenGL so far so I can't really say if there are problems or not. Be aware though that as SFML doesn't support 3D you can't use SFML's renderTexture for it, you'll have to implement your own version of renderTexture using OpenGL or use whatever a 3D engine grants for that so that you can take benefit from 3D transforms.
-
Be aware though that as SFML doesn't support 3D you can't use SFML's renderTexture for it, you'll have to implement your own version of renderTexture using OpenGL or use whatever a 3D engine grants for that so that you can take benefit from 3D transforms.
Don't take my word for it, since I've no idea about OpenGL, but you should easily be able to extract the texture from the render texture and call bind() on it to get it working with OpenGL, but maybe I'm mistaken (or one can't call bind() on the const ref texture...). ;)
-
Why a render texture? A texture doesn't have a direct graphical representation, it exists in the video memory. Do you mean you want to view a sprite from a 3D perspective?
What you can do with SFML, is to take a vertex array and to calculate the vertex positions according to the perspective transform.
-
Why a render texture? A texture doesn't have a direct graphical representation, it exists in the video memory. Do you mean you want to view a sprite from a 3D perspective?
What you can do with SFML, is to take a vertex array and to calculate the vertex positions according to the perspective transform.
Yeah sorry, I meant a sprite having a rendertexture as its texture.
The seconds part sounds interesting - is there any article on the subject?
-
You can take a look at the documentation of sf::Vertex and sf::VertexArray.
-
If you realy want to do this with sfml, there is two ways :
1. rewrite sfml math
2. write your own math, manual calculate screen space coordinates, path them to target draw (i did that, but thats a bad choice)
(not sure about raw openGl, i remember there was some problems with that)
Or you can look at osg or else (there are many choices)
-
What you can do with SFML, is to take a vertex array and to calculate the vertex positions according to the perspective transform.
As mentioned in other threads, this can be tricky. Trapezoidal transformations on quad do not work as expected ; this is because quads are acutally made of 2 triangles. The result is _not_ what one would expect of a perspective view.
http://en.sfml-dev.org/forums/index.php?topic=9466.msg64262#msg64262
-
Don't take my word for it, since I've no idea about OpenGL, but you should easily be able to extract the texture from the render texture and call bind() on it to get it working with OpenGL, but maybe I'm mistaken (or one can't call bind() on the const ref texture...).
You can generally do that in OpenGL unless you want to define mipmaps.
What I meant with your own version was precisely that, just use your normal renderTexture, bind it's texture with OpenGL and transform it as you may like according to the type of view system you may be using. You can have class that does all that.
As mentioned in other threads, this can be tricky. Trapezoidal transformations on quad do not work as expected ; this is because quads are actually made of 2 triangles. The result is _not_ what one would expect of a perspective view.
What you get is that a part of the texture overlaps with the other so it looks like a folded paper rather than an object with perspective. And if you transform it, it just gets weirder.
-
As mentioned in other threads, this can be tricky. Trapezoidal transformations on quad do not work as expected ; this is because quads are acutally made of 2 triangles. The result is _not_ what one would expect of a perspective view.
Indeed, trapezoids (central perspective) won't work. However, parallelograms (parallel perspective) are still possible.