diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 7011d6b..60047c4 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -4,4 +4,8 @@ add_executable(bettolac ${CLIENT_SOURCES} ) -target_link_libraries(bettolac PRIVATE bettola) +find_package(SDL3 REQUIRED) +find_package(GLEW REQUIRED) +find_package(OpenGL REQUIRED) + +target_link_libraries(bettolac PRIVATE bettola SDL3::SDL3 GLEW::glew OpenGL::GL) diff --git a/client/src/main.cpp b/client/src/main.cpp index d7398ed..fd1dcb4 100644 --- a/client/src/main.cpp +++ b/client/src/main.cpp @@ -1,6 +1,75 @@ -#include "bettola.h" +#include +#include +#include +#include +#include +#include +#include int main(int argc, char** argv) { - bettola_function(); + /* Init SDL. */ + if(!SDL_Init(SDL_INIT_VIDEO)) { + printf("SDL could not initialise! SDL_ERROR: %s\n", SDL_GetError()); + return 1; + } + + /* Set OpenGL attributes. */ + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + + /* Create a window. */ + SDL_Window* window = SDL_CreateWindow( + "Bettola Client", + 1280, + 720, + SDL_WINDOW_OPENGL + ); + + if(window == NULL) { + printf("Unable to create window! SDL_ERROR: %s\n", SDL_GetError()); + return 1; + } + + /* Create OpenGL context. */ + SDL_GLContext context = SDL_GL_CreateContext(window); + if(context == NULL) { + printf("OpenGL context could not be created! SDL_ERROR: %s\n", SDL_GetError()); + return 1; + } + + /* Initialise GLEW. */ + glewExperimental = GL_TRUE; + GLenum glewError = glewInit(); + if(glewError != GLEW_OK) { + printf("Error initialising GLEW! %s\n", glewGetErrorString(glewError)); + return 1; + } + + printf("SDL/OpenGL initialisation succes.\n"); + + bool running = true; + while(running) { + /* Event handling. */ + SDL_Event event; + while(SDL_PollEvent(&event)) { + if(event.type == SDL_EVENT_QUIT) { + running = false; + } + } + + /* Rendering. */ + glClearColor(0.1f, 0.1f, 0.1, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + /* It's really odd to call it SwapWindow now, rather than SwapBuffer. */ + SDL_GL_SwapWindow(window); + } + + /* Cleanup. */ + SDL_GL_DestroyContext(context); + SDL_DestroyWindow(window); + SDL_Quit(); + return 0; }