Skip to content

Commit

Permalink
Small tests for future imps
Browse files Browse the repository at this point in the history
  • Loading branch information
AsulconS committed Oct 31, 2023
1 parent 6329bf2 commit 1e0a463
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ build_cpp_source(triangle)
build_cpp_source(gyroscope)
build_cpp_source(doubleWindow)
build_cpp_source(physicsTest)
build_cpp_source(shaderTester)
8 changes: 8 additions & 0 deletions examples/shaders/test.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#version 460 core

out vec4 FragColor;

void main()
{
FragColor = vec4(0.0f, 1.0f, 0.0f, 1.0f);
}
8 changes: 8 additions & 0 deletions examples/shaders/test.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#version 460 core

layout (location = 0) in vec2 aPos;

void main()
{
gl_Position = vec4(aPos, 0.0f, 1.0f);
}
83 changes: 83 additions & 0 deletions examples/src/shaderTester.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/********************************************************************************
* *
* HSGIL - Handy Scalable Graphics Integration Library *
* Copyright (c) 2019-2023 Adrian Bedregal *
* *
* This software is provided 'as-is', without any express or implied *
* warranty. In no event will the authors be held liable for any damages *
* arising from the use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not *
* claim that you wrote the original software. If you use this software *
* in a product, an acknowledgment in the product documentation would be *
* appreciated but is not required. *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* 3. This notice may not be removed or altered from any source distribution. *
* *
********************************************************************************/

#include <HSGIL/hsgil.hpp>

#include <iostream>

int main()
{
gil::RenderingWindow window(800, 600, "Shader Tester");
if (!window.isReady())
{
std::cerr << "Window is not ready, something went wrong" << std::endl;
return -1;
}

gil::InputHandler inputHandler;
window.setInputHandler(inputHandler);

gil::Shader shader("test");
float vertexData[] =
{
// Position
-0.5f, -0.5f,
0.5f, -0.5f,
0.0f, 0.5f
};
gil::uint32 VAO, VBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);

glBindVertexArray(VAO);

glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);

glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (const void*)0);
glEnableVertexAttribArray(0);

glBindVertexArray(0);

gil::Timer timer;
while (window.isActive())
{
window.pollEvents();
if (inputHandler.onKeyDown(gil::KEY_ESCAPE))
{
window.close();
}

shader.use();
glClearColor(0.2f, 0.5f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, sizeof(vertexData) / sizeof(float));
glBindVertexArray(0);

window.swapBuffers();
timer.tick();
}

return 0;
}

0 comments on commit 1e0a463

Please sign in to comment.