Hello guys,
This issue has been adressed multiples times, but I followed every suggested solutions and nothing seems to work:
I get :
Exception thrown at 0x0000000000000000 in Program.exe: 0xC0000005: Access violation executing location 0x0000000000000000.
I already done:
-Creating a GLFW OpenGL 3.2 context with forward compatibility for the 3.0+ functionnalities to be available
-Inited in the right order GLFW > the Window context > GLEW with experimental = true
my code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "codefortress_core.h"
#include "dataparser.h"
#include "utils.h"
using namespace std;
using namespace utils;
using namespace dataparser;
// -------------------------------- MAIN ------------------------------- //
int main()
{
// -------------------------------- INIT ------------------------------- //
// Init GLFW
if (glfwInit() != GL_TRUE) {
graphic_engine::ge_crash("Failed to initialize GLFW
");
//fprintf(stderr, "Failed to initialize GLFW
");
//return -1;
}
// Create a rendering window with OpenGL 3.2 context
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //3.2 works //4.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL", NULL, NULL); //glfwGetPrimaryMonitor() avant dernier parama
glfwMakeContextCurrent(window);
if (!window)
{
fprintf(stderr, "Failed to open GLFW window.
");
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, graphic_engine::key_callback);
// Init GLEW
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
graphic_engine::ge_crash("Failed to initialize GLEW
");
//fprintf(stderr, "Failed to initialize GLEW
");
//return -1;
}
// ----------------------------- RESOURCES ----------------------------- //
//map values
const int map_size = 16;
const int spice = 28; //colored differently
int map[map_size*map_size];
for (int i = 0; i < map_size*map_size;i++) {
if (i%spice == 0) {
map[i] = 1;
}else {
map[i] = 0;
}
}
//declarations
GLuint vao;
GLuint buffer[1]; //map buffer
//first VAO
glCreateVertexArrays(1, &vao);
//buffer
glCreateBuffers(1, &buffer[0]);
glNamedBufferStorage(buffer[0],sizeof(map),map,0);
glVertexArrayVertexBuffer(vao, 0, buffer[0], 0, sizeof(int));
//attrib linked
glVertexArrayAttribFormat(vao,0,1,GL_INT,GL_FALSE,0);
glVertexArrayAttribBinding(vao, 0, 0);
glEnableVertexArrayAttrib(vao, 0);
// ---------------------------- RENDERING LOOP ------------------------------ //
static GLfloat color[] = { 0.0f,0.0f, 0.0f, 1.0f };
while (!glfwWindowShouldClose(window))
{
//flashy background
float curtime = (float)glfwGetTime();
color[0] = cosf(curtime)*0.5f + 0.5f;
color[1] = sinf(curtime)*0.5f + 0.5f;
glClearBufferfv(GL_COLOR, 0, color);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
Any help is very appreciated, thanks in advance !
(sorry for my english, and I had trouble posting, maybe I did this thread in duplicate ?)