Added Texture class

This commit is contained in:
Robert 2021-01-21 12:07:43 +01:00
parent 1b2ed0cdf5
commit e2e15dd98f
13 changed files with 8005 additions and 35 deletions

View file

@ -14,4 +14,5 @@ target_link_libraries(debug PRIVATE
add_custom_command(TARGET debug POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:openglu> $<TARGET_FILE:glfw> $<TARGET_FILE_DIR:debug>
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/shaders $<TARGET_FILE_DIR:debug>/shaders
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/assets $<TARGET_FILE_DIR:debug>/assets
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View file

@ -43,10 +43,10 @@ int main(int argc, char** argv)
// Create vertices for square
float vertices[] = {
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // top right
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, // bottom left
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f // top left
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left
};
unsigned int indices[] = {
@ -55,12 +55,13 @@ int main(int argc, char** argv)
};
oglu::VertexAttribute topology[] = {
{ 0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0 },
{ 1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)) }
{ 0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0 },
{ 1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)) },
{ 2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)) }
};
// Make a square
oglu::Object square = oglu::MakeObject(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology));
oglu::VertexArray square = oglu::MakeObject(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology));
// Create a shader
oglu::Shader shader;
@ -74,6 +75,9 @@ int main(int argc, char** argv)
return -1;
}
// Create a texture
oglu::Texture texture = oglu::MakeTexture("assets/crate.jpg");
// Window loop
while (!glfwWindowShouldClose(window))
{
@ -81,8 +85,8 @@ int main(int argc, char** argv)
oglu::ClearScreen(GL_COLOR_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
shader->SetUniform("ourColor", &oglu::Color::Transparent);
shader->Use();
texture->Bind();
square->BindAndDraw();
glfwSwapBuffers(window);

View file

@ -1,11 +1,12 @@
#version 330 core
in vec3 oCol;
in vec2 oUV;
out vec4 FragColor;
uniform vec4 ourColor;
uniform sampler2D ourTexture;
void main()
{
FragColor = vec4(oCol, 1.0f) + ourColor;
FragColor = texture(ourTexture, oUV) * vec4(oCol, 1.0);
}

View file

@ -1,11 +1,14 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aCol;
layout (location = 2) in vec2 aUV;
out vec3 oCol;
out vec2 oUV;
void main()
{
oCol = aCol;
oUV = aUV;
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}