95 lines
2.4 KiB
C++
95 lines
2.4 KiB
C++
#include <cstdio>
|
|
#include <GL/glew.h>
|
|
#include <SDL3/SDL.h>
|
|
#include <SDL3/SDL_keyboard.h>
|
|
|
|
#include "terminal.h"
|
|
|
|
const int SCREEN_WIDTH = 1280;
|
|
const int SCREEN_HEIGHT = 720;
|
|
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",
|
|
SCREEN_WIDTH,
|
|
SCREEN_HEIGHT,
|
|
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;
|
|
}
|
|
|
|
/* Configure OpenGL. */
|
|
glEnable(GL_BLEND);
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
/* Listen for text input. */
|
|
SDL_StartTextInput(window);
|
|
|
|
/* Init text renderer. */
|
|
TextRenderer* txt_render_instance = new TextRenderer(SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
txt_render_instance->load_font("assets/fonts/hack/Hack-Regular.ttf", 14);
|
|
|
|
/* Create terminal. */
|
|
Terminal* term = new Terminal();
|
|
|
|
bool running = true;
|
|
while(running) {
|
|
/* Event handling. */
|
|
SDL_Event event;
|
|
while(SDL_PollEvent(&event)) {
|
|
if(event.type == SDL_EVENT_QUIT) { running = false; }
|
|
/* Pass input to terminal. */
|
|
term->handle_input(&event);
|
|
}
|
|
|
|
/* Clear screen. */
|
|
glClearColor(0.1f, 0.1f, 0.1, 1.0f);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
/* Render text. */
|
|
float white[] = { 1.0f, 1.0f, 1.0f };
|
|
term->render(txt_render_instance);
|
|
|
|
/* It's really odd to call it SwapWindow now, rather than SwapBuffer. */
|
|
SDL_GL_SwapWindow(window);
|
|
}
|
|
|
|
/* Cleanup. */
|
|
delete term;
|
|
delete txt_render_instance;
|
|
SDL_GL_DestroyContext(context);
|
|
SDL_DestroyWindow(window);
|
|
SDL_Quit();
|
|
|
|
return 0;
|
|
}
|