87 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <cstdio>
 | 
						|
#include "gfx/txt_renderer.h"
 | 
						|
#include <GL/glew.h>
 | 
						|
#include <SDL3/SDL.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);
 | 
						|
 | 
						|
  /* Init text renderer. */
 | 
						|
  TextRenderer* txt_render_instance = new TextRenderer(SCREEN_WIDTH, SCREEN_HEIGHT);
 | 
						|
  txt_render_instance->load_font("assets/fonts/hack/Hack-Regular.ttf", 24);
 | 
						|
 | 
						|
  bool running = true;
 | 
						|
  while(running) {
 | 
						|
    /* Event handling. */
 | 
						|
    SDL_Event event;
 | 
						|
    while(SDL_PollEvent(&event)) {
 | 
						|
      if(event.type == SDL_EVENT_QUIT) {
 | 
						|
        running = false;
 | 
						|
      }
 | 
						|
    }
 | 
						|
 | 
						|
    /* 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 };
 | 
						|
    txt_render_instance->render_text("Hello World", 25.0f, SCREEN_HEIGHT - 50.0f, 
 | 
						|
                                     1.0f, white);
 | 
						|
 | 
						|
    /* It's really odd to call it SwapWindow now, rather than SwapBuffer. */
 | 
						|
    SDL_GL_SwapWindow(window);
 | 
						|
  }
 | 
						|
 | 
						|
  /* Cleanup. */
 | 
						|
  delete txt_render_instance;
 | 
						|
  SDL_GL_DestroyContext(context);
 | 
						|
  SDL_DestroyWindow(window);
 | 
						|
  SDL_Quit();
 | 
						|
 | 
						|
  return 0;
 | 
						|
}
 |