I should have the newest version of Glew and Glfw so that shouldn't be the problem. Everything should be linked, and I'm using MS visual studio 2019. When i run the code, it show an error: "Unhandled exception at 0xEF04B530 in b1.exe: 0xC0000005: Access violation executing location 0x00000000". I think error in "void Init()" function . How can i fix it? Thanks
#include "glew.h"
#include "glfw3.h"
#include<iostream>
using namespace std;
#define numVAOs 1
GLuint rederingProgram;
GLuint vao[numVAOs];
GLuint createShaderProgram()
{
const char* vshaderSource =
"#version 430 \n"
"void main(void)\n"
"{gl_Position = vec4(0,0,0,1};";
const char* fshaderSource =
"#version 430 \n"
"out vec4 color;\n"
"void main(void)\n"
"{color = vec4(1,1,1,1};";
GLuint vShader = glCreateShader(GL_VERTEX_SHADER);
GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(vShader, 1, &vshaderSource, NULL);
glShaderSource(fShader, 1, &fshaderSource, NULL);
glCompileShader(vShader);
glCompileShader(fShader);
GLuint vfProgram = glCreateProgram();
glAttachShader(vfProgram, vShader);
glAttachShader(vfProgram, fShader);
glLinkProgram(vfProgram);
return vfProgram;
}
void init(GLFWwindow* window)
{
rederingProgram = createShaderProgram();
glGenVertexArrays(numVAOs, vao);
glBindVertexArray(vao[0]);
}
void display(GLFWwindow* window, double currentTime)
{
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(rederingProgram);
glDrawArrays(GL_POINTS, 0, 1);
}
int main()
{
if (!glfwInit())
{
exit(0);
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
GLFWwindow* window = glfwCreateWindow(600,600,"b1",NULL,NULL);
glfwMakeContextCurrent(window);
if (glewInit() != GLEW_OK)
{
exit(0);
}
glfwSwapInterval(1);
init(window);
while (!glfwWindowShouldClose(window))
{
display(window, glfwGetTime());
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
exit(0);
}
User contributions licensed under CC BY-SA 3.0