-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGLWindow.cpp
More file actions
80 lines (63 loc) · 1.97 KB
/
Copy pathGLWindow.cpp
File metadata and controls
80 lines (63 loc) · 1.97 KB
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
#include "pch.h"
#include "GLWindow.h"
#include <assert.h>
#include <memory>
#include "VertexBuffer.h"
#include "FragmentShader.h"
#include "VertexShader.h"
#include "ShaderProgram.h"
#include "ElementBufferObj.h"
#include "GLTexture.h"
GLWindow::GLWindow(int width, int height)
{
GlInitializer glInit(width, height);
//ustawienie callback do zmiany rozmiaru
glfwSetFramebufferSizeCallback(glInit.getWin().get(), [](GLFWwindow* window, int _width, int _height) {
glViewport(0, 0, _width, _height);
});
FragmentShader framgentShader;
VertexShader vertShader;
auto shProgram = ShaderProgram::create();
shProgram->addShader(vertShader);
shProgram->addShader(framgentShader);
shProgram->link();
VertexBuffer buffer(
{
{0.5f, 0.5f, 0.0f}, // top right
{0.5f, -0.5f, 0.0f}, // bottom right
{-0.5f, -0.5f, 0.0f},
{-0.5f, 0.5f, 0.0f}// bottom left
},
/*
{ {1, 1, 1},//colors
{1, 1, 1},
{1, 1, 1}
},*/
{//text
{1, 1}, // lower-left corner
{1, 0}, // lower-right corner
{0, 0},
{0, 1}
});
buffer.setIndexes({ 0, 1, 2,
0, 3, 2 });
GLTexture texture;
texture.loadFromFile("..\\..\\tekstura.jpg");
shProgram->use();
glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
glEnable(GL_DEPTH_TEST);
mat4 view(1.0f);
view = translate(view, { 0.0f, 0.0f, -3.0f});
vertShader.setViewMat(view);
vertShader.setDefaultPerspective(width, height);
while (!glfwWindowShouldClose(glInit.getWin().get()))
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mat4 trans = mat4(1.0f);
trans = rotate(trans, (float)glfwGetTime(), { 1, 0, 0 });
vertShader.setWorldMat(trans);
buffer.draw();
glfwSwapBuffers(glInit.getWin().get());
glfwPollEvents();
}
}