1) I just started using the sf::VertexArray class. From what I can tell glTranslate is not "compatible". I cannot seem to move the vertex array object around the screen using glTranslate. Should I be using sf::Transform to reposition the object?
2) In order to draw a triangle using raw opengl while also drawing an object with sf::VertexArray, I *have* to wrap the VA call with window.pushGLStates(); window.popGLStates(); lines. Does anybody know why this is the case?
#include <SFML/Graphics.hpp>
#include <GL/gl.h>
#include <GL/glu.h>
int main() {
std::vector<sf::VideoMode> VModes = sf::VideoMode::getFullscreenModes();
sf::RenderWindow window(sf::VideoMode(VModes[0].width, VModes[0].height), "SFML window", sf::Style::Fullscreen);
window.setFramerateLimit(60);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)VModes[0].width/(GLfloat)VModes[0].height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
while (1) {
sf::Event event;
while(window.pollEvent(event)) {
if(event.type == sf::Event::Closed) { goto CLEANUP; }
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { goto CLEANUP; }
}
window.clear();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-6.0f);
// triangle
glBegin(GL_POLYGON);
glVertex3f( 0.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
window.pushGLStates();
glTranslatef(3.0f, 0.0f, 0.0f);
// another triangle that ignores glTranslatef on my machine from what i can tell
sf::VertexArray triangle(sf::Triangles, 3);
triangle[0].position = sf::Vector2f(100, 100);
triangle[1].position = sf::Vector2f(200, 100);
triangle[2].position = sf::Vector2f(200, 200);
triangle[0].color = sf::Color::Red;
triangle[1].color = sf::Color::Blue;
triangle[2].color = sf::Color::Green;
window.draw(triangle);
window.popGLStates();
window.display();
}
if(0) {
CLEANUP:
window.close();
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}