76 lines
1.8 KiB
C++
76 lines
1.8 KiB
C++
#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) {
|
|
/* 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;
|
|
}
|