I am doing the same code on a RenderWindow and a RenderImage, but looks that the RenderImage is not working for me.
That's the code using a RenderWindow
int main()
{
// Window
sf::RenderWindow window;
window.Create(sf::VideoMode(800, 600), "What?");
// Setup OpenGL
glClearColor(1.f, 0.f, 0.f, 1.f);
glClearDepth(1.f);
glEnable(GL_DEPTH_TEST);
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);
// Clear
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Setup camera
glLoadIdentity();
glTranslatef(0.f, 0.f, -100.f);
// Draw something
glColor4f(0.f, 0.f, 1.f, 1.f);
glBegin(GL_POLYGON);
{
glVertex2f(-10.f, -10.f);
glVertex2f(-10.f, 10.f);
glVertex2f(10.f, 10.f);
glVertex2f(10.f, -10.f);
}
glEnd();
// Display and wait
window.Display();
while(window.IsOpened())
{
sf::Event event;
while(window.GetEvent(event))
{
if(event.Type == sf::Event::Closed) window.Close();
}
}
}
and the output
Uploaded with
ImageShack.usThis is the code for the RenderImage
int main()
{
// Render image
sf::RenderImage image;
image.Create(800, 600);
// Setup OpenGL
glClearColor(1.f, 0.f, 0.f, 1.f);
glClearDepth(1.f);
glEnable(GL_DEPTH_TEST);
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);
// Clear
glClearColor(1.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Setup camera
glLoadIdentity();
glTranslatef(0.f, 0.f, -100.f);
// Draw something
glColor4f(0.f, 0.f, 1.f, 1.f);
glBegin(GL_POLYGON);
{
glVertex2f(-10.f, -10.f);
glVertex2f(-10.f, 10.f);
glVertex2f(10.f, 10.f);
glVertex2f(10.f, -10.f);
}
glEnd();
// Image
image.Display();
image.GetImage().SaveToFile("image.png");
}
and the output image.png
Uploaded with
ImageShack.usI am using W7x64 with VS2010. Am I forgetting something? glClear works, but not the polygon itself.