<commit_before>/*
	libsoundbag

	Copyright (c) 2017 <NAME>

	This software released under MIT License
	http://opensource.org/licenses/mit-license.php
*/
#include <GL/gl.h>
#include "SDL.h"

#include "soundbag/SDL_GL_Window.hpp"

using namespace soundbag;

SDL_GL_Window::SDL_GL_Window( const char* title, const SDL_GL_Window::Config* conf ) throw( std::runtime_error )
	: frame_rate( conf->frame_rate )
{
	uint32_t flags = SDL_WINDOW_OPENGL;

	if( conf->window_mode == Config::WINDOW_MODE_FULLSCREEN ){
		flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
	}
	else if( conf->window_mode == Config::WINDOW_MODE_MAXIMIZED ){
		flags |= SDL_WINDOW_MAXIMIZED;
	}
	else if( conf->window_mode == Config::WINDOW_MODE_MINIMIZED ){
		flags |= SDL_WINDOW_MINIMIZED;
	}

	window = SDL_CreateWindow( title, conf->x, conf->y, conf->width, conf->height, flags );
	if( window == NULL ){
		throw std::runtime_error("Failed to create window.");
	}

	context = SDL_GL_CreateContext(window);
	if( context == NULL ){
		throw std::runtime_error("Failed to create OpenGL context.");
	}

	onResize( conf->width, conf->height );

	setBackground( conf->background );

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );

	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
	glDisable(GL_LIGHTING);
}

SDL_GL_Window::~SDL_GL_Window(){
	SDL_DestroyWindow(window);
}

void SDL_GL_Window::onResize( int w, int h ){
	width  = w;
	height = h;
	glViewport( 0, 0, w, h );
	setProjection();
}

void SDL_GL_Window::setProjection(){
	const double w = getWidth();
	const double h = getHeight();
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho( -w/2, w/2, -h/2, h/2, -1.0, 1.0 );
}

void SDL_GL_Window::prepare(){

}

void SDL_GL_Window::main(){
	prepare();

	SDL_Event event;
	const uint32_t interval = 1000 / frame_rate;
	uint32_t tick = SDL_GetTicks();
	uint32_t next_frame = tick;
	uint32_t last_frame = tick;
	quit = false;
	while(!quit){
		while( SDL_PollEvent(&event) ){
			if( handleEvent(event) ){
				continue;
			}
			else if( SDL_QUIT ){<commit_msg>FIx condition for SDL_QUIT<commit_after>/*
	libsoundbag

	Copyright (c) 2017 <NAME>

	This software released under MIT License
	http://opensource.org/licenses/mit-license.php
*/
#include <GL/gl.h>
#include "SDL.h"

#include "soundbag/SDL_GL_Window.hpp"

using namespace soundbag;

SDL_GL_Window::SDL_GL_Window( const char* title, const SDL_GL_Window::Config* conf ) throw( std::runtime_error )
	: frame_rate( conf->frame_rate )
{
	uint32_t flags = SDL_WINDOW_OPENGL;

	if( conf->window_mode == Config::WINDOW_MODE_FULLSCREEN ){
		flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
	}
	else if( conf->window_mode == Config::WINDOW_MODE_MAXIMIZED ){
		flags |= SDL_WINDOW_MAXIMIZED;
	}
	else if( conf->window_mode == Config::WINDOW_MODE_MINIMIZED ){
		flags |= SDL_WINDOW_MINIMIZED;
	}

	window = SDL_CreateWindow( title, conf->x, conf->y, conf->width, conf->height, flags );
	if( window == NULL ){
		throw std::runtime_error("Failed to create window.");
	}

	context = SDL_GL_CreateContext(window);
	if( context == NULL ){
		throw std::runtime_error("Failed to create OpenGL context.");
	}

	onResize( conf->width, conf->height );

	setBackground( conf->background );

	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );

	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);
	glDisable(GL_LIGHTING);
}

SDL_GL_Window::~SDL_GL_Window(){
	SDL_DestroyWindow(window);
}

void SDL_GL_Window::onResize( int w, int h ){
	width  = w;
	height = h;
	glViewport( 0, 0, w, h );
	setProjection();
}

void SDL_GL_Window::setProjection(){
	const double w = getWidth();
	const double h = getHeight();
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho( -w/2, w/2, -h/2, h/2, -1.0, 1.0 );
}

void SDL_GL_Window::prepare(){

}

void SDL_GL_Window::main(){
	prepare();

	SDL_Event event;
	const uint32_t interval = 1000 / frame_rate;
	uint32_t tick = SDL_GetTicks();
	uint32_t next_frame = tick;
	uint32_t last_frame = tick;
	quit = false;
	while(!quit){
		while( SDL_PollEvent(&event) ){
			if( handleEvent(event) ){
				continue;
			}
			else if( enevt.type == SDL_QUIT ){
{'fraction_non_alphanumeric': 0.13904125924159313, 'fraction_numerical': 0.014786549010255187, 'mean_word_length': 5.122627737226277, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6472914', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1601, 'n_words': 328}