Sure, sorry, it took so long. I am using dynamic SFML2, haven't tried static.
I use last revision.
The last two functions are used to provide a 2D projection (taking OpenGL units as pixels).
//////////////////////////////////////////////////////////////////////////
// Headers
//////////////////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
// Forward declarations
void glEnable2D();
void glDisable2D();
//////////////////////////////////////////////////////////////////////////
// Main
//////////////////////////////////////////////////////////////////////////
int main()
{
// Data
sf::RenderImage surface;
sf::Image image;
// Load an image
image.LoadFromFile("floor.png");
// Create and activate surface
surface.Create(800, 600);
surface.SetActive(true);
// - ATTENTION, PROBLEM HERE -
// Draw an empty sprite (uncomment this to make this program work)
{
//sf::Sprite sprite;
//surface.Draw(sprite);
}
// - ATTENTION, PROBLEM HERE
// Initialize OpenGL for rendering to surface
{
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_ONE, GL_ONE);
glDepthMask(GL_TRUE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 3000.f);
glMatrixMode(GL_MODELVIEW);
}
// Bind loaded image
image.Bind();
// Draw image to surface
glEnable2D();
glBegin(GL_QUADS);
{
glTexCoord2f(0.f, 1.f); glVertex2f(0, 0);
glTexCoord2f(0.f, 0.f); glVertex2f(0, 200);
glTexCoord2f(1.f, 0.f); glVertex2f(200, 200);
glTexCoord2f(1.f, 1.f); glVertex2f(200, 0);
}
glEnd();
glDisable2D();
// Update surface pixels
surface.Display();
// Save surface to file
surface.GetImage().SaveToFile("surface.png");
/*
Now it's supposed to see the image floor.png drawn to surface.png,
but it isn't as long as you uncomment the code above
*/
}
//////////////////////////////////////////////////////////////////////////
// Enable 2D projection
//////////////////////////////////////////////////////////////////////////
void glEnable2D()
{
static int vPort[4];
glGetIntegerv(GL_VIEWPORT, vPort);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(vPort[0], vPort[0]+vPort[2], vPort[1], vPort[1]+vPort[3], -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.375f, 0.375f, 0.f);
glPushAttrib(GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
}
//////////////////////////////////////////////////////////////////////////
// Disable 2D projection
//////////////////////////////////////////////////////////////////////////
void glDisable2D()
{
glPopAttrib();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}