Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Can't draw with OpenGL in sf::RenderImage  (Read 2616 times)

0 Members and 1 Guest are viewing this topic.

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Can't draw with OpenGL in sf::RenderImage
« on: November 09, 2010, 10:52:02 am »
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
Code: [Select]
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.us

This is the code for the RenderImage
Code: [Select]
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.us

I am using W7x64 with VS2010. Am I forgetting something? glClear works, but not the polygon itself.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Can't draw with OpenGL in sf::RenderImage
« Reply #1 on: November 09, 2010, 12:23:22 pm »
The code looks good, I'll test that as soon as possible.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Can't draw with OpenGL in sf::RenderImage
« Reply #2 on: November 09, 2010, 09:49:24 pm »
You forgot to call glViewport.
Laurent Gomila - SFML developer

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
Can't draw with OpenGL in sf::RenderImage
« Reply #3 on: November 09, 2010, 10:00:50 pm »
Quote from: "Laurent"
You forgot to call glViewport.

Oh, thanks! Why should I write more code in the RenderImage section? I suppose it's because the internal configuration.
EDIT: Oh I guessed, it's because RenderWindow sets the viewport with its width and height.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Can't draw with OpenGL in sf::RenderImage
« Reply #4 on: November 09, 2010, 10:11:05 pm »
Quote
Oh, thanks! Why should I write more code in the RenderImage section? I suppose it's because the internal configuration.
EDIT: Oh I guessed, it's because RenderWindow sets the viewport with its width and height.

I think it's OpenGL. In SFML, both RenderWindow and RenderImage have the same initialization. Whereas in OpenGL, they are two very different things.
Laurent Gomila - SFML developer