We now have a triangle :D
This commit is contained in:
parent
3291732dd3
commit
3652cd82d4
2 changed files with 81 additions and 53 deletions
4
Makefile
4
Makefile
|
|
@ -9,6 +9,8 @@ BUILDDIR = build/
|
|||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(SRCDIR)main.cpp
|
||||
$(TARGET): $(SRCDIR)main.cpp $(BUILDDIR)
|
||||
$(CC) $(CFLAGS) -o $(BUILDDIR)$(TARGET) $(SRCDIR)main.cpp
|
||||
|
||||
$(BUILDDIR):
|
||||
mkdir -p $(BUILDDIR)
|
||||
|
|
|
|||
30
src/main.cpp
30
src/main.cpp
|
|
@ -1,5 +1,6 @@
|
|||
//#include <iostream>
|
||||
#include <GL/glew.h>
|
||||
// Make sure Glew is loaded first
|
||||
#include <GL/gl.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
|
|
@ -38,10 +39,34 @@ int main(int argc, char ** argv){
|
|||
// TODO: Throw an error lol
|
||||
}
|
||||
|
||||
|
||||
// Create event handling struct
|
||||
SDL_Event input;
|
||||
|
||||
// test triangle
|
||||
float vertices[] = {-0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f};
|
||||
|
||||
// Vertex Buffer Object
|
||||
unsigned int VBO;
|
||||
glGenBuffers(1, &VBO);
|
||||
|
||||
// Bind the buffer and size it to the data provided
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
|
||||
// Create vertex array that will populate buffer
|
||||
unsigned int VAO;
|
||||
glCreateVertexArrays(1, &VAO);
|
||||
glEnableVertexArrayAttrib(VAO, 0);
|
||||
|
||||
// set up vertex array atributes
|
||||
glVertexArrayAttribFormat(VAO, 0, 3, GL_FLOAT, GL_FALSE, 0);
|
||||
|
||||
// sut up vbo for vao
|
||||
glVertexArrayVertexBuffer(VAO, 0, VBO, 0, sizeof(float) * 3);
|
||||
|
||||
// shove vertex array into buffer
|
||||
glBindVertexArray(VAO);
|
||||
|
||||
// Game loop
|
||||
bool running = true;
|
||||
while (running) {
|
||||
|
|
@ -52,13 +77,14 @@ int main(int argc, char ** argv){
|
|||
running = false;
|
||||
}
|
||||
// TODO: Do something with keys lol
|
||||
|
||||
};
|
||||
// Clear screen ready for next loop
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// TODO: Run game here lol
|
||||
// Draw triangle
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue