I'm trying to build a program that utilises both OpenGL 4.5 and SFML graphics module. I've been following along with the
tutorial but I can't seem to get any of the graphics module code rendering too.
I'm not sure if it's a profile related issue or not, but any help would be greatly appreciated. I'll post the Shader class as an attatchment, since I'm sure the issue is in this example:
#include <GL/glew.h>
#include <SFML/OpenGL.hpp>
#include "Shader.h"
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(500,500), "sfOpengl", sf::Style::Default);
sf::RectangleShape rect(sf::Vector2f(50, 50));
rect.setFillColor(sf::Color::Magenta);
GLuint VBO;
GLuint VAO;
Shader* shader = NULL;
shader = new Shader("shaders/triangle.vs", "shaders/triangle.fs");
GLfloat vertices[9] = {
-0.5f, -0.5, 0.f,
0.5f, -0.5f, 0.f,
0.f, 0.5f, 0.f };
glewInit();
glewExperimental = GL_TRUE;
bool running = true;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
// Position attribute
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
// Colour attribute
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
glBindVertexArray(0);
while (running)
{
sf::Event event;
while(window.pollEvent(event))
{
if(event.type == sf::Event::Closed)
{
running = false;
}
}
window.pushGLStates();
glClearColor(0.2f, 0.3f, 0.3f, 0.1f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Drawing the triangle
shader->use();
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
glDisableVertexAttribArray(0);
window.popGLStates();
window.resetGLStates();
window.draw(rect);
window.display();
}
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
delete shader;
return 0;
}