Hello guys,
I know This issue has been addressed many times, but despite trying every solutions given for this problem, I can’t seem to solve the issue:
I get:
Exception thrown at 0x0000000000000000 in codefortress_client.exe: 0xC0000005: Access violation executing location 0x0000000000000000.
What I have done:
-Created an OpenGL 3.2 context with forward compatibility for 3.0+…
-Init in the right order GLFW > Window context > GLEW with experimental= true
#include <stdio.h>
#include <stdlib.h>
//#include <windows.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;
}
}
//declaration
GLuint vao;
GLuint buffer[1]; //map buffer
//first VAO
glCreateVertexArrays(1, &vao);
//buffer
glCreateBuffers(1, &buffer[0]);
glNamedBufferStorage(buffer[0],sizeof(map),map,0); //fill with map
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;
}
Some help would be very appreciated, thank you in advance.