Форум программистов, компьютерный форум, киберфорум
Наши страницы
8Observer8
Войти
Регистрация
Восстановить пароль
Рейтинг: 5.00. Голосов: 1.

Configuration of Visual Studio Project for using C++, OpenGL 3+, FreeGLUT and static GLEW

Запись от 8Observer8 размещена 02.02.2019 в 15:34
Обновил(-а) 8Observer8 02.02.2019 в 15:54

Configuration: All Configurations; Platforms: All Platforms
C/C++ -> Genaral -> Additional Include Directories:

$(SolutionDir).\Libs\glm-0.9.8.4
$(SolutionDir).\Libs\glew-2.0.0-win32\include
$(SolutionDir).\Libs\freeglut-MSVC-3.0.0-2.mp\freeglut\include
Linker -> Input -> Additional Dependencies
freeglut.lib
glew32s.lib

Configuration: All Configurations; Platforms: Win32
Linker -> General -> Additional Library Directories:

$(SolutionDir).\Libs\glew-2.0.0-win32\lib\Platform_Win32
$(SolutionDir).\Libs\freeglut-MSVC-3.0.0-2.mp\freeglut\lib\Platform_Win32
Build Events -> Post-Build Event
xcopy /y /d $(SolutionDir)Libs\freeglut-MSVC-3.0.0-2.mp\freeglut\freeglut_bin\Platform_Win32\freeglut.dll $(OutDir)

Configuration: All Configurations; Platforms: x64
Linker -> General -> Additional Library Directories:

$(SolutionDir).\Libs\glew-2.0.0-win32\lib\Platform_x64
$(SolutionDir).\Libs\freeglut-MSVC-3.0.0-2.mp\freeglut\lib\Platform_x64
Build Events -> Post-Build Event
xcopy /y /d $(SolutionDir)Libs\freeglut-MSVC-3.0.0-2.mp\freeglut\freeglut_bin\Platform_x64\freeglut.dll $(OutDir)

All libraries are included in the project: DrawingLine.rar

Note. Select your version of VS in Platform Toolset:

Screenshot


main.cpp
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#define GLEW_STATIC
 
#include <GL/glew.h>
#include <GL/freeglut.h>
 
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
 
#include <string>
#include <iostream>
using namespace std;
 
extern "C" _declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
 
const char *vertexShaderSource =
"#version 330\n \
 \
in vec2 a_Position; \
 \
void main()\
{ \
    gl_Position = vec4(a_Position, 0.0, 1.0); \
    gl_PointSize = 10.0; \
}";
 
const char *fragmentShaderSource =
"#version 330\n \
 \
precision mediump float; \
out vec4 fragColor; \
 \
void main()\
{ \
    fragColor = vec4(1.0, 0.0, 0.0, 1.0); \
}";
 
void CheckShaderCompileStatus(GLuint shader)
{
    GLint status;
    glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
        glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
        GLchar *infoLog = new GLchar[infoLogLength];
        glGetShaderInfoLog(shader, infoLogLength, NULL, infoLog);
        cerr << "Compile log: " << infoLog << endl;
        delete[] infoLog;
    }
}
GLuint vao;
void Display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glBindVertexArray(vao);
    glDrawArrays(GL_LINES, 0, 2);
    glutSwapBuffers();
}
 
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitContextVersion(3, 3);
    glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG);
    glutInitWindowSize(500, 500);
 
    string title = "Drawing a line";
    glutCreateWindow(title.c_str());
    cout << title << endl;
 
    glewInit();
 
    GLuint vShader = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(vShader, 1, &vertexShaderSource, NULL);
    glCompileShader(vShader);
    CheckShaderCompileStatus(vShader);
 
    GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER);
    glShaderSource(fShader, 1, &fragmentShaderSource, NULL);
    glCompileShader(fShader);
    CheckShaderCompileStatus(fShader);
 
    GLuint program = glCreateProgram();
    glAttachShader(program, vShader);
    glAttachShader(program, fShader);
    glLinkProgram(program);
    glUseProgram(program);
    GLint status;
    glGetProgramiv(program, GL_LINK_STATUS, &status);
    if (status == GL_FALSE)
    {
        GLint infoLogLength;
 
        glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
        GLchar *infoLog = new GLchar[infoLogLength];
        glGetProgramInfoLog(program, infoLogLength, NULL, infoLog);
        cerr << "Link log: " << infoLog << endl;
        delete[] infoLog;
    }
 
    GLfloat vertices[] = { 0.0f, 0.0f, 0.5f, 0.5f };
 
    GLuint vbo;
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, 4 * sizeof(GLfloat), vertices, GL_STATIC_DRAW);
 
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
    glEnableVertexAttribArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
 
    GLint a_Position = glGetAttribLocation(program, "a_Position");
    glVertexAttribPointer(a_Position, 2, GL_FLOAT, GL_FALSE, 0, NULL);
    glEnableVertexAttribArray(a_Position);
 
    glEnable(GL_PROGRAM_POINT_SIZE);
 
    glutDisplayFunc(Display);
 
    glutMainLoop();
    return 0;
Размещено в Без категории
Просмотров 89 Комментарии 0
Всего комментариев 0
Комментарии
 
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Рейтинг@Mail.ru