Skip to content

Commit 0106f13

Browse files
author
beryll1um
committed
ret(texture): texture example returned
1 parent 92d77bd commit 0106f13

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

examples/texture/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
project(texture)
2+
3+
add_executable(${PROJECT_NAME} "${PROJECT_NAME}.cpp")
4+
target_link_libraries(${PROJECT_NAME} PUBLIC ${UNIFIED_PROJECT})
5+
6+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/image.png
7+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

examples/texture/image.png

40.5 KB
Loading

examples/texture/texture.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <unified.hpp>
2+
3+
#include <unified/graphics/2d/drawable/texture.hpp>
4+
5+
using namespace Unified;
6+
using namespace Unified::Graphics;
7+
8+
class TextureLayer : public Layer
9+
{
10+
public:
11+
12+
const Application *application;
13+
14+
Graphics2D::Texture texture;
15+
16+
Graphics::Vertex2d quad_vertices[4] =
17+
{ { { -0.8, -0.8 }, { 1.0, 1.0 } },
18+
{ { -0.8, 0.8 }, { 1.0, 0.0 } },
19+
{ { 0.8, 0.8 }, { 0.0, 0.0 } },
20+
{ { 0.8, -0.8 }, { 0.0, 1.0 } } };
21+
22+
TextureLayer(Application *application) : application(application), texture("image.png") {
23+
texture.write(quad_vertices, sizeof(quad_vertices));
24+
}
25+
26+
virtual void OnUpdate(Time) override {
27+
application->draw(texture);
28+
}
29+
30+
};
31+
32+
class ExampleLayers : public Application
33+
{
34+
public:
35+
36+
void window_resize_event(const WindowResizeEvent &event) {
37+
set_viewport(event.size);
38+
}
39+
40+
public:
41+
42+
ExampleLayers() : Application("ExampleTexture") {
43+
push_layer<TextureLayer>(this);
44+
set_frame_limit(60);
45+
}
46+
47+
virtual bool OnUpdate(Time) override {
48+
clear({ 0.15, 0.15, 0.15 });
49+
process_layers();
50+
swap_buffers();
51+
return poll_events();
52+
}
53+
54+
virtual void OnEvent(EventDispatcher &dispatcher) override {
55+
dispatcher.dispatch<WindowResizeEvent>(BIND_EVENT_FN(&ExampleLayers::window_resize_event, this));
56+
}
57+
58+
};
59+
60+
Application *UNIFIED_NAMESPACE::CreateApplication() {
61+
return new ExampleLayers();
62+
}

src/graphics/render_target.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ UNIFIED_GRAPHICS_BEGIN_NAMESPACE
88
RenderTarget::RenderTarget() {
99
if (!gladLoadGL())
1010
throw Exceptions::initialization_failed("failed to initialize glad");
11+
12+
glEnable(GL_BLEND);
13+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1114
}
1215

1316
void RenderTarget::clear(const Color &color) {

0 commit comments

Comments
 (0)