Что делать, при запуске кода выдает ошибку:
1>Main.obj : error LNK2019: ссылка на неразрешенный внешний символ __imp_glClear в функции main.
1>Main.obj : error LNK2019: ссылка на неразрешенный внешний символ __imp_glDrawArrays в функции main.
1>E:\cod\cod\x64\Debug\cod.exe : fatal error LNK1120: неразрешенных внешних элементов: 2
Вот сам код:
#include <GL/glew.h>
#include <glfw3.h>
#include <iostream>
const char* vertexShaderSource = R"(
#version 330 core
layout (location = 0) in vec2 aPos;
uniform vec2 lightPos;
void main()
{
gl_Position = vec4(aPos, 0.0, 1.0);
}
)";
const char* fragmentShaderSource = R"(
#version 330 core
out vec4 FragColor;
uniform vec2 lightPos;
void main()
{
vec2 pos = gl_FragCoord.xy / 800.0 * 2.0 - 1.0;
float distance = length(pos - lightPos);
float intensity = 1.0 / (1.0 + 10.0 * distance * distance);
FragColor = vec4(intensity, intensity, intensity, 1.0);
}
)";
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "2D Point Light Example", nullptr, nullptr);
if (!window)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
{
std::cout << "Failed to initialize GLEW" << std::endl;
return -1;
}
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexShaderSource, nullptr);
glCompileShader(vertexShader);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentShaderSource, nullptr);
glCompileShader(fragmentShader);
GLuint shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
float vertices[] = {
-0.05f, -0.05f,
0.05f, -0.05f,
0.05f, 0.05f,
0.05f, 0.05f,
-0.05f, 0.05f,
-0.05f, -0.05f
};
GLuint VAO, VBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
glUseProgram(shaderProgram);
GLint lightPosLoc = glGetUniformLocation(shaderProgram, "lightPos");
glUniform2f(lightPosLoc, 0.0f, 0.0f);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);
glfwSwapBuffers(window);
glfwPollEvents();
}
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteProgram(shaderProgram);
glfwTerminate();
return 0;
}