Add stb_image so we can begin texture work
This commit is contained in:
parent
ef03920fa6
commit
2141e9d338
File diff suppressed because it is too large
Load Diff
Binary file not shown.
After Width: | Height: | Size: 161 B |
|
@ -1,6 +1,7 @@
|
|||
add_executable(Exponent
|
||||
main.cc
|
||||
GLProgramLoader.cc
|
||||
stb_image.cc
|
||||
)
|
||||
|
||||
target_link_libraries(Exponent PUBLIC glfw glm::glm)
|
||||
|
|
36
src/main.cc
36
src/main.cc
|
@ -18,6 +18,8 @@
|
|||
#include <glm/ext.hpp>
|
||||
#include <glm/mat2x2.hpp>
|
||||
|
||||
#include <stb/stb_image.h>
|
||||
|
||||
static void dbg_log(const char* str) {
|
||||
std::cout << str << std::endl;
|
||||
}
|
||||
|
@ -58,15 +60,15 @@ static void init_shaders() {
|
|||
rotate_unif = glGetUniformLocation(g_program_id, "rotation");
|
||||
}
|
||||
|
||||
class Triangle {
|
||||
class Quad {
|
||||
public:
|
||||
GLfloat data[6];
|
||||
float m_pos_x;
|
||||
float m_pos_y;
|
||||
float rotation = 0.2f;
|
||||
GLfloat data[12];
|
||||
float m_pos_x = 0;
|
||||
float m_pos_y = 0;
|
||||
float rotation = 0.0f;
|
||||
|
||||
Triangle(std::array<glm::vec2, 3> verts) {
|
||||
for (std::size_t i = 0; i < 3; i++) {
|
||||
Quad(std::array<glm::vec2, 6> verts) {
|
||||
for (std::size_t i = 0; i < 6; i++) {
|
||||
data[i*2] = verts[i][0];
|
||||
data[i*2+1] = verts[i][1];
|
||||
}
|
||||
|
@ -81,10 +83,15 @@ static GLuint vertex_buf[2];
|
|||
static GLuint array_buf[2];
|
||||
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.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
|
||||
|
@ -98,7 +105,7 @@ static void init_opengl() {
|
|||
|
||||
glGenBuffers(2, vertex_buf);
|
||||
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);
|
||||
glEnableVertexAttribArray(vertex_data_position);
|
||||
|
||||
|
@ -133,7 +140,12 @@ int main() {
|
|||
|
||||
// Main Loop
|
||||
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);
|
||||
|
||||
|
@ -141,7 +153,7 @@ int main() {
|
|||
glUniform1f(rotate_unif, o1.rotation);
|
||||
|
||||
glBindVertexArray(array_buf[0]);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
glfwSwapBuffers(w);
|
||||
glfwPollEvents();
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb/stb_image.h>
|
Loading…
Reference in New Issue