Skip to content

Commit

Permalink
Porting to GLFW3
Browse files Browse the repository at this point in the history
  • Loading branch information
ginkgo committed Nov 3, 2018
1 parent 9d7c33e commit cc0f51a
Show file tree
Hide file tree
Showing 20 changed files with 2,010 additions and 6,564 deletions.
2 changes: 1 addition & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env['LIBS'] = ['GLU', 'GL', 'protobuf', 'IL']
env['CPPPATH'] = ['#', '#/src', '#/external/tinyXML', '#/external/flextGL/', '/usr/include/OpenEXR']

env.ParseConfig("pkg-config IlmBase --cflags --libs")
env.ParseConfig("pkg-config libglfw --cflags --libs")
env.ParseConfig("pkg-config glfw3 --cflags --libs")
env.ParseConfig("pkg-config ftgl --cflags --libs")
env.ParseConfig("pkg-config sigc++-2.0 --cflags --libs")
env.ParseConfig("pkg-config SDL_mixer --cflags --libs")
Expand Down
353 changes: 152 additions & 201 deletions external/flextGL/flextGL.c

Large diffs are not rendered by default.

7,912 changes: 1,710 additions & 6,202 deletions external/flextGL/flextGL.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions glprofile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
version 2.0 compatibility

extension EXT_framebuffer_object required
extension ARB_texture_float required

extension ARB_geometry_shader4 optional
extension EXT_transform_feedback optional
Expand Down
14 changes: 7 additions & 7 deletions src/Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Config::Config()
: width(800),
height(600),
window_mode(GLFW_FULLSCREEN),
window_mode(FULLSCREEN),
fsaa_samples(4),
swap_interval(1),
polygon_mode(GL_FILL),
Expand Down Expand Up @@ -108,7 +108,7 @@ void Config::set_value(string name, string value)

int ival = 0;
float fval = 0.0f;
int winmodeval = GLFW_WINDOW;
WindowMode winmodeval = WINDOW;
GLenum polymodeval = GL_FILL;
string sval = "";
V2f vec2val;
Expand Down Expand Up @@ -151,11 +151,11 @@ void Config::set_value(string name, string value)
bval = ival; // Try to parse as integer (0/1)
}

if (value.find("window") != string::npos &&
value.find("window") < value.find(';')) {
winmodeval = GLFW_WINDOW;
if (value.find("fullscreen") != string::npos &&
value.find("fullscreen") < value.find(';')) {
winmodeval = FULLSCREEN;
} else {
winmodeval = GLFW_FULLSCREEN;
winmodeval = WINDOW;
}

if (value.find("fill") != string::npos &&
Expand Down Expand Up @@ -321,7 +321,7 @@ bool Config::write_file(string filename)
os << "height = " << height << ";" << endl;
os << "swap_interval = " << swap_interval << ";" << endl;
os << "window_mode = ";
if (window_mode == GLFW_WINDOW)
if (window_mode == WINDOW)
os << "window;" << endl;
else
os << "fullscreen;" << endl;
Expand Down
7 changes: 6 additions & 1 deletion src/Config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@

#include "cinquo.hh"

enum WindowMode {
FULLSCREEN,
WINDOW
};

class Config
{
public:


// Window properties:
int width, height;
int window_mode;
WindowMode window_mode;
int fsaa_samples;
int swap_interval;
GLenum polygon_mode;
Expand Down
136 changes: 61 additions & 75 deletions src/Menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

Menu* Menu::callback_menu = NULL;

void GLFWCALL menu_mouse_callback(int button, int action)
void menu_mouse_callback(GLFWwindow* window, int button, int action, int mods)
{
if (Menu::callback_menu != NULL)
Menu::callback_menu->mouse_callback(button, action);
}

void GLFWCALL menu_resize_callback(int width, int height)
void menu_resize_callback(GLFWwindow* window, int width, int height)
{
if (Menu::callback_menu != NULL)
Menu::callback_menu->resize_callback(width, height);
}

void GLFWCALL menu_key_callback(int key, int state)
void menu_key_callback(GLFWwindow* window, int key, int scancode, int state, int mods)
{
if (state != GLFW_PRESS || Menu::callback_menu == NULL )
return;
Expand All @@ -34,7 +34,7 @@ void GLFWCALL menu_key_callback(int key, int state)

void Menu::toggle_fullscreen(void)
{
config->window_mode = (config->window_mode == GLFW_WINDOW)?GLFW_FULLSCREEN:GLFW_WINDOW;
config->window_mode = (config->window_mode == WINDOW)?FULLSCREEN:WINDOW;
status = RESET;
running = false;
}
Expand All @@ -48,9 +48,9 @@ void Menu::toggle_music(void)

void Menu::mouse_callback(int button, int action)
{
int x,y;
double x,y;

glfwGetMousePos(&x, &y);
glfwGetCursorPos(window, &x, &y);

if (action == GLFW_PRESS) {
V2f pos(x,screen_size.y - y);
Expand Down Expand Up @@ -84,7 +84,8 @@ void Menu::resize_callback(int width, int height)
#define TEXT_COLOR Color4f(1,1,1,0.5)

Menu::Menu (Config* config,
Skydome* skydome)
Skydome* skydome,
GLFWwindow* window)
: active_screen(MAIN_SCREEN),
config(config),
skydome(skydome),
Expand All @@ -98,36 +99,37 @@ Menu::Menu (Config* config,
prev_level_button(config->resource_dir + "textures/left.png"),
computer_no("0", config),
human_no("0", config),
computer_text(config->resource_dir + "textures/computer.png"),
human_text(config->resource_dir + "textures/human.png"),
computers(config->ai_count),
humans(config->player_count - config->ai_count),
settings_text("Settings", config),
settings_done(config->resource_dir + "textures/back.png"),
particles_text("Some particles", config, TEXT_COLOR),
prev_particles(config->resource_dir + "textures/left.png"),
next_particles(config->resource_dir + "textures/right.png"),
fullscreen_text("Some particles", config, TEXT_COLOR),
prev_fullscreen(config->resource_dir + "textures/left.png"),
next_fullscreen(config->resource_dir + "textures/right.png"),
minimap_text("Some particles", config, TEXT_COLOR),
prev_minimap(config->resource_dir + "textures/left.png"),
next_minimap(config->resource_dir + "textures/right.png"),
antialiasing_text("Some particles", config, TEXT_COLOR),
prev_antialiasing(config->resource_dir + "textures/left.png"),
next_antialiasing(config->resource_dir + "textures/right.png"),
hearts_text("Some particles", config, TEXT_COLOR),
prev_hearts(config->resource_dir + "textures/left.png"),
next_hearts(config->resource_dir + "textures/right.png"),
resolution_text("Some particles", config, TEXT_COLOR),
prev_resolution(config->resource_dir + "textures/left.png"),
next_resolution(config->resource_dir + "textures/right.png"),
water_text("Simple water", config, TEXT_COLOR),
prev_water(config->resource_dir + "textures/left.png"),
next_water(config->resource_dir + "textures/right.png"),
needs_reset(false),
computer_slider(config),
human_slider(config)
computer_text(config->resource_dir + "textures/computer.png"),
human_text(config->resource_dir + "textures/human.png"),
computers(config->ai_count),
humans(config->player_count - config->ai_count),
settings_text("Settings", config),
settings_done(config->resource_dir + "textures/back.png"),
particles_text("Some particles", config, TEXT_COLOR),
prev_particles(config->resource_dir + "textures/left.png"),
next_particles(config->resource_dir + "textures/right.png"),
fullscreen_text("Some particles", config, TEXT_COLOR),
prev_fullscreen(config->resource_dir + "textures/left.png"),
next_fullscreen(config->resource_dir + "textures/right.png"),
minimap_text("Some particles", config, TEXT_COLOR),
prev_minimap(config->resource_dir + "textures/left.png"),
next_minimap(config->resource_dir + "textures/right.png"),
antialiasing_text("Some particles", config, TEXT_COLOR),
prev_antialiasing(config->resource_dir + "textures/left.png"),
next_antialiasing(config->resource_dir + "textures/right.png"),
hearts_text("Some particles", config, TEXT_COLOR),
prev_hearts(config->resource_dir + "textures/left.png"),
next_hearts(config->resource_dir + "textures/right.png"),
resolution_text("Some particles", config, TEXT_COLOR),
prev_resolution(config->resource_dir + "textures/left.png"),
next_resolution(config->resource_dir + "textures/right.png"),
water_text("Simple water", config, TEXT_COLOR),
prev_water(config->resource_dir + "textures/left.png"),
next_water(config->resource_dir + "textures/right.png"),
needs_reset(false),
window(window),
computer_slider(config),
human_slider(config)

{
getErrors();
Expand All @@ -136,7 +138,7 @@ Menu::Menu (Config* config,
load_levels(config->resource_dir + config->levels_file);

int w,h;
glfwGetWindowSize(&w,&h);
glfwGetWindowSize(window, &w,&h);
resize_callback(w,h);

next_level(0);
Expand All @@ -151,32 +153,16 @@ Menu::Menu (Config* config,

void Menu::setup_settings(void)
{
GLFWvidmode vidmodes[100];

int modes_found = glfwGetVideoModes(vidmodes, 100);
int modes_found;
const GLFWvidmode* vidmodes = glfwGetVideoModes(glfwGetPrimaryMonitor(), &modes_found);

resolutions.resize(modes_found);

for (int i = 0; i < modes_found; ++i) {
resolutions[i] = V2i(vidmodes[i].Width,
vidmodes[i].Height);
resolutions[i] = V2i(vidmodes[i].width,
vidmodes[i].height);
}

// resolutions.push_back(V2i( 640, 480));
// resolutions.push_back(V2i( 800, 600));
// resolutions.push_back(V2i( 960, 600));
// resolutions.push_back(V2i(1024, 768));
// resolutions.push_back(V2i(1280, 720));
// resolutions.push_back(V2i(1280, 768));
// resolutions.push_back(V2i(1280, 800));
// resolutions.push_back(V2i(1280,1024));
// resolutions.push_back(V2i(1440, 900));
// resolutions.push_back(V2i(1600,1200));
// resolutions.push_back(V2i(1680,1050));
// resolutions.push_back(V2i(1920,1080));
// resolutions.push_back(V2i(2560,1440));
// resolutions.push_back(V2i(2560,1600));

if(!config->use_particles) {
particle_setting = 0;
} else if (config->pony_particle_rate <= 10.0) {
Expand All @@ -187,7 +173,7 @@ void Menu::setup_settings(void)
particle_setting = 3;
}

if (config->window_mode == GLFW_WINDOW) {
if (config->window_mode == WINDOW) {
fullscreen_setting = 0;
} else {
fullscreen_setting = 1;
Expand Down Expand Up @@ -242,10 +228,10 @@ void Menu::load_settings(void)

if (fullscreen_setting == 0) {
fullscreen_text.set_text("Window");
config->window_mode = GLFW_WINDOW;
config->window_mode = WINDOW;
} else {
fullscreen_text.set_text("Fullscreen");
config->window_mode = GLFW_FULLSCREEN;
config->window_mode = FULLSCREEN;
}

if (minimap_setting == 0) {
Expand Down Expand Up @@ -693,16 +679,16 @@ void Menu::reload_level(string level)

Menu::MenuStatus Menu::run(void)
{
if (config->window_mode == GLFW_FULLSCREEN)
glfwEnable(GLFW_MOUSE_CURSOR);
if (config->window_mode == FULLSCREEN)
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);

status = START;
running = true;

callback_menu = this;
glfwSetMouseButtonCallback(menu_mouse_callback);
glfwSetWindowSizeCallback(menu_resize_callback);
glfwSetKeyCallback(menu_key_callback);
glfwSetMouseButtonCallback(window, menu_mouse_callback);
glfwSetWindowSizeCallback(window, menu_resize_callback);
glfwSetKeyCallback(window, menu_key_callback);


while (running) {
Expand All @@ -713,25 +699,25 @@ Menu::MenuStatus Menu::run(void)

draw();

glfwSwapBuffers();
glfwSwapBuffers(window);

if (glfwGetKey( GLFW_KEY_ESC ) ||
!glfwGetWindowParam( GLFW_OPENED )) {
if (glfwGetKey( window, GLFW_KEY_ESCAPE ) ||
glfwWindowShouldClose( window )) {
status = QUIT;
running = false;
} else if (glfwGetKey(GLFW_KEY_ENTER)) {
} else if (glfwGetKey( window, GLFW_KEY_ENTER)) {
status = START;
running = false;
}
}

glfwSetMouseButtonCallback(NULL);
glfwSetWindowSizeCallback(NULL);
glfwSetKeyCallback(NULL);
glfwSetMouseButtonCallback(window, NULL);
glfwSetWindowSizeCallback(window, NULL);
glfwSetKeyCallback(window, NULL);
callback_menu = NULL;

if (config->window_mode == GLFW_FULLSCREEN)
glfwDisable(GLFW_MOUSE_CURSOR);
if (config->window_mode == FULLSCREEN)
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);

return status;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Menu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ class Menu

bool needs_reset;

GLFWwindow* window;

public:

void toggle_fullscreen(void);
void toggle_music(void);

Menu(Config* config,
Skydome* skydome);
Skydome* skydome,
GLFWwindow* window);

MenuStatus run(void);

Expand All @@ -147,6 +150,7 @@ class Menu
void next_level(int d);

static Menu* callback_menu;

};

#endif
23 changes: 13 additions & 10 deletions src/Pony.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,35 @@ Pony::Decision PlayerPony::decide(PonyGame* game, int i)
float& accel = decision.acceleration;
float& steer = decision.steer;

if (glfwGetKey(up) == GLFW_PRESS)
GLFWwindow* window = game->get_window();

if (glfwGetKey(window, up) == GLFW_PRESS)
accel += 1.0;
if (glfwGetKey(down) == GLFW_PRESS)
if (glfwGetKey(window, down) == GLFW_PRESS)
accel -= 1.0;

if (glfwGetKey(left) == GLFW_PRESS)
if (glfwGetKey(window, left) == GLFW_PRESS)
steer += 1.0;
if (glfwGetKey(right) == GLFW_PRESS)
if (glfwGetKey(window, right) == GLFW_PRESS)
steer -= 1.0;

if (glfwGetJoystickParam(i,GLFW_PRESENT) == GL_TRUE) {
if (glfwJoystickPresent(i) == GL_TRUE) {

int n;
const float* axes_c = glfwGetJoystickAxes(i,&n);
float axes[10];

int n = glfwGetJoystickPos(i,axes,10);

std::copy(axes_c, axes_c+n, axes);
if (n >= 2) {

if (fabs(axes[0]) < 0.2) axes[0] = 0.0;
//accel += axes[1];
steer -= axes[0]*2;
}

unsigned char buttons[20];

int button_count = glfwGetJoystickButtons(i, buttons, 20);
int button_count;
const unsigned char* buttons = glfwGetJoystickButtons(i, &button_count);

if (button_count >= 2) {
if (buttons[0] == GLFW_PRESS)
Expand Down
Loading

0 comments on commit cc0f51a

Please sign in to comment.