Add stb_image so we can begin texture work

This commit is contained in:
Archie Hilton 2024-05-11 20:10:10 +01:00
parent ef03920fa6
commit 2141e9d338
5 changed files with 8012 additions and 12 deletions

7985
include/stb/stb_image.h Normal file

File diff suppressed because it is too large Load Diff

BIN
res/tex/util/missing.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

View File

@ -1,6 +1,7 @@
add_executable(Exponent add_executable(Exponent
main.cc main.cc
GLProgramLoader.cc GLProgramLoader.cc
stb_image.cc
) )
target_link_libraries(Exponent PUBLIC glfw glm::glm) target_link_libraries(Exponent PUBLIC glfw glm::glm)

View File

@ -18,6 +18,8 @@
#include <glm/ext.hpp> #include <glm/ext.hpp>
#include <glm/mat2x2.hpp> #include <glm/mat2x2.hpp>
#include <stb/stb_image.h>
static void dbg_log(const char* str) { static void dbg_log(const char* str) {
std::cout << str << std::endl; std::cout << str << std::endl;
} }
@ -58,15 +60,15 @@ static void init_shaders() {
rotate_unif = glGetUniformLocation(g_program_id, "rotation"); rotate_unif = glGetUniformLocation(g_program_id, "rotation");
} }
class Triangle { class Quad {
public: public:
GLfloat data[6]; GLfloat data[12];
float m_pos_x; float m_pos_x = 0;
float m_pos_y; float m_pos_y = 0;
float rotation = 0.2f; float rotation = 0.0f;
Triangle(std::array<glm::vec2, 3> verts) { Quad(std::array<glm::vec2, 6> verts) {
for (std::size_t i = 0; i < 3; i++) { for (std::size_t i = 0; i < 6; i++) {
data[i*2] = verts[i][0]; data[i*2] = verts[i][0];
data[i*2+1] = verts[i][1]; data[i*2+1] = verts[i][1];
} }
@ -81,10 +83,15 @@ static GLuint vertex_buf[2];
static GLuint array_buf[2]; static GLuint array_buf[2];
static const GLuint vertex_data_position = 0; static const GLuint vertex_data_position = 0;
static Triangle o1(std::array<glm::vec2, 3>({ static Quad o1(std::array<glm::vec2, 6>({
// Tri 2
{0.0f, 0.0f}, {0.0f, 0.0f},
{0.5f, 0.0f}, {0.5f, 0.0f},
{0.5f, 0.5f} {0.5f, 0.5f},
// Tri 1
{0.0f, 0.0f},
{0.5f, 0.5f},
{0.0f, 0.5f},
})); }));
// Do the work of initialising opengl so we can draw stuff // Do the work of initialising opengl so we can draw stuff
@ -98,7 +105,7 @@ static void init_opengl() {
glGenBuffers(2, vertex_buf); glGenBuffers(2, vertex_buf);
glBindBuffer(GL_ARRAY_BUFFER, vertex_buf[0]); glBindBuffer(GL_ARRAY_BUFFER, vertex_buf[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(Triangle::data), o1.data, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, sizeof(Quad::data), o1.data, GL_STATIC_DRAW);
glVertexAttribPointer(vertex_data_position, 2, GL_FLOAT, GL_FALSE, 0, NULL); glVertexAttribPointer(vertex_data_position, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glEnableVertexAttribArray(vertex_data_position); glEnableVertexAttribArray(vertex_data_position);
@ -133,7 +140,12 @@ int main() {
// Main Loop // Main Loop
while(!glfwWindowShouldClose(w)) { while(!glfwWindowShouldClose(w)) {
float time = glfwGetTime(); float time = glfwGetTime();
o1.rotation = 2*sin(time);
o1.m_pos_x = 0.25*sin(time);
o1.m_pos_y = 0.5*cos(time);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
@ -141,7 +153,7 @@ int main() {
glUniform1f(rotate_unif, o1.rotation); glUniform1f(rotate_unif, o1.rotation);
glBindVertexArray(array_buf[0]); glBindVertexArray(array_buf[0]);
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 6);
glfwSwapBuffers(w); glfwSwapBuffers(w);
glfwPollEvents(); glfwPollEvents();

2
src/stb_image.cc Normal file
View File

@ -0,0 +1,2 @@
#define STB_IMAGE_IMPLEMENTATION
#include <stb/stb_image.h>