triangle has now colors

This commit is contained in:
2026-04-13 01:32:31 +02:00
parent 64b27a6b84
commit 0c74cf691f
7 changed files with 46 additions and 18 deletions

View File

@@ -31,7 +31,7 @@ GLuint Shader::compile(std::string shaderSource, GLenum shaderType) {
glGetShaderiv(id, GL_INFO_LOG_LENGTH, &length);
char* message = new char[length];
glGetShaderInfoLog(id, length, &length, message);
std::cout << "Shader Compilation Error" << message << std::endl;
std::cout << "Shader Compilation Error [" << "None" << "] " << message << std::endl;
delete[] message;
return 0;
}

View File

@@ -19,10 +19,12 @@ int main() {
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
uint32 flags = SDL_WINDOW_OPENGL; //| SDL_WINDOW_FULLSCREEN;
SDL_Window* window = SDL_CreateWindow(
"Cinecraft",
800, 600,
SDL_WINDOW_OPENGL
flags
);
SDL_GLContext context = SDL_GL_CreateContext(window);
@@ -35,9 +37,9 @@ int main() {
std::cout << "OpenGL Version: " << glGetString(GL_VERSION) << std::endl;
Vertex vertices[] = {
Vertex{-0.5f, -0.5f, 0.0f},
Vertex{0.0f, 0.5f, 0.0f},
Vertex{0.5f, -0.5f, 0.0f},
Vertex{-0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f},
Vertex{0.0f, 0.5f, 0.0f, 0.0, 1.0f, 0.0f, 1.0f},
Vertex{0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f},
};
uint32_t numVertices = 3;
@@ -47,15 +49,16 @@ int main() {
Shader shader("shaders/basic.vert", "shaders/basic.frag");
shader.bind();
const uint64 perfCounterFrequency = SDL_GetPerformanceFrequency();
uint64 lastCounter = SDL_GetPerformanceCounter();
float32 delta = 0.0f;
// WIREFRAME
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
bool running = true;
SDL_Event e;
while (running) {
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) {
running = false;
}
}
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
@@ -65,6 +68,19 @@ int main() {
vertexBuffer.unbind();
SDL_GL_SwapWindow(window);
while (SDL_PollEvent(&e)) {
if (e.type == SDL_EVENT_QUIT) {
running = false;
}
}
const uint64 endCounter = SDL_GetPerformanceCounter();
const uint64 counterElapsed = endCounter - lastCounter;
delta = (static_cast<float32>(counterElapsed) / static_cast<float32>(perfCounterFrequency));
const auto FPS = static_cast<uint32>(static_cast<float32>(perfCounterFrequency) / static_cast<float32>(counterElapsed));
std::cout << "FPS: " << FPS << std::endl;
lastCounter = endCounter;
}
SDL_GL_DestroyContext(context);