CC = gcc
CXX = g++
DEFINES = -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN
CFLAGS = -fno-keep-inline-dllexport -g -Wall -W -Wextra $(DEFINES)
CXXFLAGS = -fno-keep-inline-dllexport -g -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads $(DEFINES)
INCPATH = -I..\learning -I. -I..\..\..\..\Qt\5.11.2\mingw53_32\include -I..\..\..\..\Qt\5.11.2\mingw53_32\include\QtGui -I..\..\..\..\Qt\5.11.2\mingw53_32\include\QtANGLE -I..\..\..\..\Qt\5.11.2\mingw53_32\include\QtCore -Idebug -I..\..\..\..\Qt\5.11.2\mingw53_32\mkspecs\win32-g++
LINKER = g++
LFLAGS = -Wl,-subsystem,windows -mthreads
LIBS = -lmingw32 -LC:\Qt\5.11.2\mingw53_32\lib C:\Qt\5.11.2\mingw53_32\lib\libqtmaind.a -LC:\openssl\lib -LC:\Utils\my_sql\mysql-5.6.11-win32\lib -LC:\Utils\postgresql\pgsql\lib -lshell32 -lglfw3 -lgdi32 -lglew32 -lopengl32 C:\Qt\5.11.2\mingw53_32\lib\libQt5Guid.a C:\Qt\5.11.2\mingw53_32\lib\libQt5Cored.a
QMAKE = C:\Qt\5.11.2\mingw53_32\bin\qmake.exe
#include <windows.h>
#include <vector>
//#include <typeinfo.h>
#include <iterator>
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
bool side = true;
GLFWwindow* window = 0;
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
// Когда пользователь нажимает ESC, мы устанавливаем свойство WindowShouldClose в true,
// и приложение после этого закроется
if(key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
int main() {
if (!glfwInit()) {
fprintf(stderr, "ERROR: could not start GLFW3\n");
return 1;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(640, 480, "first", 0, 0);
if (window == 0)
{
//std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
glewInit();
const GLubyte* renderer = glGetString(GL_RENDERER); // get renderer string
const GLubyte* version = glGetString(GL_VERSION); // version as a string
printf("Renderer: %s\n", renderer);
printf("OpenGL version supported %s\n", version);
glEnable(GL_DEPTH_TEST); // enable depth-testing
glDepthFunc(GL_LESS); // depth-testing interprets a smaller value as "closer"
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
GLfloat ourColor[] = {0.2f, 0.3f, 0.6f, 1.0f};
const GLchar* const vertexSource =
"#version 400\n"
"in vec3 position;"
"void main(){"
"gl_Position = vec4(position.x, position.y, position.z, 1.0);}\0";
const GLchar* const fragmentSource =
"#version 330 core\n"
"uniform vec4 ourColor;"
"out vec4 color;"
"void main(){"
"color = ourColor;}\0";
GLuint vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertexSource, NULL);
glCompileShader(vertexShader);
GLint success;
GLchar infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if(!success)
{
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
}else{
cout << "Success init vertex shader\n";
}
GLuint fragmentShader;
vertexShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
glCompileShader(fragmentShader);
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if(!success)
{
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
}else{
cout << "Success init fragment shader\n";
}
GLuint shaderProgram;
shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if(!success)
{
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
}else{
cout << "Success link shader's program\n";
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
GLfloat vertexTriangle[] = {
-0.5f, -0.5f, 0.0f, //левый нижний
0.5f, -0.5f, 0.0f, //правый нижний
0.0f, 0.5f, 0.0f //верхний
};
GLuint VBO, VAO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), vertexTriangle, GL_DYNAMIC_DRAW);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
bool sideY = true;
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
while(!glfwWindowShouldClose(window))
{
sideY++;
GLuint VBO, VAO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(GLfloat), vertexTriangle, GL_DYNAMIC_DRAW);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLfloat timeValue = glfwGetTime();
GLfloat greenValue = (sin(timeValue) / 2) + 0.5;
GLint vertexColorLocation = glGetUniformLocation(shaderProgram, "ourColor");
glUseProgram(shaderProgram);
glUniform4f(vertexColorLocation, 0.0f, greenValue, 0.0f, 1.0f);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwPollEvents();
glfwSwapBuffers(window);
}
glfwTerminate();
return 0;
}
g++ main.cpp -o main.exe -lglfw3 //Компиляция происходит без проблем, а линковка дает ошибки