Hi,
I try draw simple triangle (OpenGL) with simple sprite and font.
#include <SFML\Graphics.hpp>
#include <GL\glew.h>
GLuint program = 0, vao = 0;
namespace OpenGL
{
void Initialize()
{
glewExperimental = true;
glewInit();
static const char * vs_source[] =
{
"#version 420 core \n"
" \n"
"void main(void) \n"
"{ \n"
" const vec4 vertices[] = vec4[](vec4( 1, -1, 0.5, 1.0), \n"
" vec4(-1, -1, 0.5, 1.0), \n"
" vec4( 0.0, 1.0, 0.5, 1.0)); \n"
" \n"
" gl_Position = vertices[gl_VertexID]; \n"
"} \n"
};
static const char * fs_source[] =
{
"#version 420 core \n"
" \n"
"out vec4 color; \n"
" \n"
"void main(void) \n"
"{ \n"
" color = vec4(0.0, 0.8, 1.0, 1.0); \n"
"} \n"
};
program = glCreateProgram();
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fs, 1, fs_source, nullptr);
glCompileShader(fs);
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vs, 1, vs_source, nullptr);
glCompileShader(vs);
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
}
void glRender()
{
static const GLfloat green[] = { 0.0f, 0.25f, 0.0f, 1.0f };
//glClearBufferfv(GL_COLOR, 0, green);
glClearColor(0.0f, 0.25f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(program);
glDrawArrays(GL_TRIANGLES, 0, 3);
}
void Shutdown()
{
glDeleteVertexArrays(1, &vao);
glDeleteProgram(program);
}
};
int main()
{
sf::ContextSettings glContextSettings;
glContextSettings.majorVersion = 4;
glContextSettings.minorVersion = 2;
glContextSettings.antialiasingLevel = 8;
glContextSettings.depthBits = 24;
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML and OpenGL 4.x or 3.2+ test",
sf::Style::Default,glContextSettings);
sf::Texture tex;
tex.loadFromFile("CHAPTER1.TGA");
sf::Sprite sprite;
sprite.setTexture(tex);
sf::Font font;
font.loadFromFile("Ubuntu-R.ttf");
sf::Text text;
text.setFont(font);
text.setString("test string");
OpenGL::Initialize();
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
OpenGL::glRender();
window.pushGLStates();
window.draw(sprite);
window.draw(text);
window.popGLStates();
window.display();
}
OpenGL::Shutdown();
return 0;
}
The result I get this error: