[Add] Initialise SDL and OpenGL window.
This commit is contained in:
parent
3272d126fd
commit
c3ebd0e501
@ -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)
|
||||
|
||||
@ -1,6 +1,75 @@
|
||||
#include "bettola.h"
|
||||
#include <cstdio>
|
||||
#include <GL/glew.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_error.h>
|
||||
#include <SDL3/SDL_events.h>
|
||||
#include <SDL3/SDL_oldnames.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user