-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cc
More file actions
78 lines (58 loc) · 2.08 KB
/
Copy pathmain.cc
File metadata and controls
78 lines (58 loc) · 2.08 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
#include <iostream>
#include <memory>
#include "frames/Graphics/OpenGL/RendererOpenGL.h"
#include "frames/Graphics/OpenGL/TextureOpenGL.h"
#include "frames/Graphics/Texture/TextureDescriptor.h"
#include "frames/Graphics/SpriteSheet/SpriteSheet.h"
#include "tools/image.h"
int main() {
// this creates a window
frames::RendererOpenGL renderer{};
// create a context object
frames::Context ctx;
frames::vec2f size{};
// an openGL texture object
frames::TextureOpenGL texture(1200u, 800u, 3u, const_cast<char*>(data));
const auto& descriptor = texture.getTextureDescriptor();
// create a sprite from the
const auto sprite1 = descriptor.createSprite({100, 100}, {600, 600});
ctx.clear();
// ctx.beginTriangles();
// ctx.drawRect({0, 0}, {1, 1});
// ctx.drawRect({-1, -1}, {0, 0});
// ctx.endTriangles();
// ctx.beginLines();
// ctx.drawLine({-0.5f, 0.5f}, {0, 0});
// ctx.endLines();
// ctx.beginTriangles();
// ctx.drawRect({0, 0}, {20, 20});
// ctx.drawRect({20, 20}, {40, 40});
// ctx.drawRect({0,0}, {1, 1});
// ctx.constructRect({0, 0}, {20, 20}, sprite1);
// ctx.endTriangles();
using namespace std::literals::string_view_literals;
renderer.shader.registerUniform("projection"sv);
renderer.shader.registerUniform("sprite_sheet"sv);
// steps to use a texture...
int textureSlot = 0;
// this step is not necessary in a loop
// 1. activate texture slot 0
glActiveTexture(GL_TEXTURE0 + textureSlot);
// 2. bind the target texture to texture 0
glBindTexture(GL_TEXTURE_2D, texture.getNativeHandle());
// this step is only necessary if using more than one texture...
// 3. set the uniform variable to use texture slot 0
renderer.shader.setInt("sprite_sheet"sv, textureSlot);
ctx.pushTexture(0);
ctx.beginTriangles();
// using namespace std::string_view_literals;
// ctx.drawString({60.f, 60.f}, "string_view"sv);
ctx.constructRect({0, 0}, {200, 200}, frames::Color(1,1,1,1), sprite1);
ctx.endTriangles();
// ctx.popTexture();
renderer.build(&ctx);
while (renderer.isOpen()) {
renderer.draw(&ctx);
}
return 0;
};