What do you mean? If you don't draw SFML stuff it still crashes?
Only SFML drawing works, but only OpenGL drawing crashes and both combined crashes, too.
Yes, I will do it later this day.
Here is a minimal example. Window creation and Glew initialization are successful and there are no OpenGL errors.
main.cpp
#pragma once
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
#include <GLEW/glew.h>
#include <SFML/OpenGL.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
using namespace sf;
#include <GLM/glm.hpp>
#include <GLM/gtc/matrix_transform.hpp>
#include <GLM/gtc/type_ptr.hpp>
using namespace glm;
int main()
{
// window
RenderWindow window(VideoMode(1024, 768), "Window Title");
window.resetGLStates();
window.setVerticalSyncEnabled(true);
cout << "Window creation " << (window.isOpen() ? "success" : "fail") << endl;
// setup
auto result = glewInit();
cout << "Glew initialization " << (result == GLEW_OK ? "success" : "fail") << endl;
glViewport(0, 0, 1024, 768);
glClearColor(.4f,.6f,.9f,0.f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
// shader
GLuint vertex = glCreateShader(GL_VERTEX_SHADER);
string vertex_string((istreambuf_iterator<char>(ifstream("shaders/basic.vert"))), istreambuf_iterator<char>());
const GLchar* vertex_chars = vertex_string.c_str();
glShaderSource(vertex, 1, &vertex_chars, NULL);
glCompileShader(vertex);
GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER);
string fragment_string((istreambuf_iterator<char>(ifstream("shaders/basic.frag"))), istreambuf_iterator<char>());
const GLchar* fragment_chars = fragment_string.c_str();
glShaderSource(fragment, 1, &fragment_chars, NULL);
glCompileShader(fragment);
GLuint program = glCreateProgram();
glAttachShader(program, vertex);
glAttachShader(program, fragment);
glLinkProgram(program);
glUseProgram(program);
mat4 Projection = perspective(45.f, 4.f / 3.f, 1.0f, 1000.f);
glUniformMatrix4fv(glGetUniformLocation(program, "projection"), 1, GL_FALSE, value_ptr(Projection));
mat4 View = lookAt(vec3(1.2f, 1.2f, 1.2f), vec3(0.0f, 0.0f, 0.0f), vec3(0.0f, 0.0f, 1.0f));
glUniformMatrix4fv(glGetUniformLocation(program, "view"), 1, GL_FALSE, value_ptr(View));
mat4 Model = translate(mat4(1), vec3(0)) * scale(mat4(1), vec3(1));
glUniformMatrix4fv(glGetUniformLocation(program, "model"), 1, GL_FALSE, value_ptr(Model));
// form
const GLfloat VERTICES[] = {-1.,-1.,1.,1.,-1.,1.,1.,1.,1.,-1.,1.,1.,-1.,1.,1.,1.,1.,1.,1.,1.,-1.,-1.,1.,-1.,1.,-1.,-1.,-1.,-1.,-1.,-1.,1.,-1.,1.,1.,-1.,-1.,-1.,-1.,1.,-1.,-1.,1.,-1.,1.,-1.,-1.,1.,-1.,-1.,-1.,-1.,-1.,1.,-1.,1.,1.,-1.,1.,-1.,1.,-1.,1.,1.,-1.,-1.,1.,1.,-1.,1.,1.,1.};
const GLfloat NORMALS[] = {0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,1,0,0,1,0,0,1,0,0,1,0,0};
const GLuint ELEMENTS[] = {0,1,2,2,3,0,4,5,6,6,7,4,8,9,10,10,11,8,12,13,14,14,15,12,16,17,18,18,19,16,20,21,22,22,23,20};
GLuint Vertices, Normals, Elements;
glGenBuffers(1, &Vertices);
glBindBuffer(GL_ARRAY_BUFFER, Vertices);
glBufferData(GL_ARRAY_BUFFER, 72 * sizeof(GLfloat), VERTICES, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenBuffers(1, &Normals);
glBindBuffer(GL_ARRAY_BUFFER, Normals);
glBufferData(GL_ARRAY_BUFFER, 72 * sizeof(GLfloat), NORMALS, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenBuffers(1, &Elements);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Elements);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 36 * sizeof(GLuint), ELEMENTS, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
// draw
while(window.isOpen())
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, Vertices);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, Normals);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Elements);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, (void*)0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
window.display();
}
}
shaders/basic.vert
#version 330
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
out vec3 fposition;
out vec3 fnormal;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
mat4 mvp = projection * view * model;
gl_Position = mvp * vec4(position, 1.0);
fnormal = (view * transpose(inverse(model)) * vec4(normal, 0.0)).xyz;
}
shaders/basic.frag
#version 330 core
in vec3 fposition;
in vec3 fnormal;
out vec3 color;
void main()
{
color = vec3(1.0, 1.0, 1.0);
}
This is the result.
Unhandled exception at 0x5E2174E3 (nvoglv32.dll) in Application.exe: 0xC0000005: Access violation reading location 0x00000000.
I think this issue is SFML related since third-party games perform correctly. I would like if you could help me.