Compare commits
No commits in common. "29cfe699ccfe6984be38cb75423e4ce502154938" and "6e25741cc9a9021ddb64e8ec6846eae807bad8a2" have entirely different histories.
29cfe699cc
...
6e25741cc9
@ -21,11 +21,11 @@
|
|||||||
# distribution.
|
# distribution.
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
project(TrippyCube C CXX)
|
project(TrippyCube CXX)
|
||||||
|
|
||||||
# Binary filename
|
# Binary filename
|
||||||
set(TARGET_NAME "trippy-cube")
|
set(TARGET_NAME "trippy-cube")
|
||||||
set(TARGET_VERSION "v2.1")
|
set(TARGET_VERSION "v2.0")
|
||||||
|
|
||||||
# Use DEBUG by default
|
# Use DEBUG by default
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
71
src/args.h
71
src/args.h
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018 Ortega Froysa, Nicolás <nortega@themusicinnoise.net> All rights reserved.
|
|
||||||
* Author: Ortega Froysa, Nicolás <nortega@themusicinnoise.net>
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "globals.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
#include <argp.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
const char *argp_program_version = VERSION;
|
|
||||||
const char *argp_program_bug_address = "nortega@themusicinnoise.net";
|
|
||||||
|
|
||||||
static char desc[] = "A psychedelic cube that changes color in 3D.";
|
|
||||||
static struct argp_option opts[] = {
|
|
||||||
{ "fullscreen", 'f', 0, 0, "Set window to fullscreen", 0 },
|
|
||||||
{ "screen-width", 'w', "width", 0, "Set width of resolution", 0 },
|
|
||||||
{ "screen-height", 'h', "height", 0, "Set height of resolution", 0 },
|
|
||||||
{ 0, 0, 0, 0, 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct args {
|
|
||||||
int fullscreen;
|
|
||||||
unsigned short width, height;
|
|
||||||
};
|
|
||||||
|
|
||||||
static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|
||||||
struct args *args = (struct args*)state->input;
|
|
||||||
switch(key)
|
|
||||||
{
|
|
||||||
case 'f':
|
|
||||||
args->fullscreen = 1;
|
|
||||||
break;
|
|
||||||
case 'w':
|
|
||||||
args->width = (unsigned short)atoi(arg);
|
|
||||||
break;
|
|
||||||
case 'h':
|
|
||||||
args->height = (unsigned short) atoi(arg);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return ARGP_ERR_UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct argp argp = { opts, parse_opt, 0, desc, 0, 0, 0 };
|
|
||||||
}
|
|
@ -38,7 +38,7 @@ void camera::update(const input *in_sys) {
|
|||||||
std::get<1>(pos) = dist * sin(yaw);
|
std::get<1>(pos) = dist * sin(yaw);
|
||||||
std::get<2>(pos) = dist * cos(yaw) * cos(angle);
|
std::get<2>(pos) = dist * cos(yaw) * cos(angle);
|
||||||
|
|
||||||
dist -= static_cast<float>(in_sys->get_scroll()) / 2.5f;
|
dist -= in_sys->get_scroll();
|
||||||
if(dist < 0.0f)
|
if(dist < 0)
|
||||||
dist = 0.0f;
|
dist = 0;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const float color_shift = 0.005;
|
const float color_shift = 0.0001;
|
||||||
void shift_colors();
|
void shift_colors();
|
||||||
|
|
||||||
// OpenGL buffers
|
// OpenGL buffers
|
||||||
|
@ -31,10 +31,9 @@
|
|||||||
# define VERSION "version"
|
# define VERSION "version"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern "C" {
|
#define SCREEN_WIDTH 800
|
||||||
extern unsigned short screen_width;
|
#define SCREEN_HEIGHT 600
|
||||||
extern unsigned short screen_height;
|
|
||||||
extern SDL_Window *window;
|
extern SDL_Window *window;
|
||||||
extern GLuint program_id;
|
extern GLuint program_id;
|
||||||
extern GLuint matrix_id;
|
extern GLuint matrix_id;
|
||||||
}
|
|
@ -93,9 +93,6 @@ void input::set_key(SDL_Keysym key, bool value) {
|
|||||||
case SDLK_d:
|
case SDLK_d:
|
||||||
actions["move_right"] = value;
|
actions["move_right"] = value;
|
||||||
break;
|
break;
|
||||||
case SDLK_ESCAPE:
|
|
||||||
case SDLK_q:
|
|
||||||
actions["quit"] = value;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
23
src/main.cpp
23
src/main.cpp
@ -24,45 +24,32 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include <argp.h>
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
|
|
||||||
#include "args.h"
|
#include "globals.hpp"
|
||||||
#include "shaders.hpp"
|
#include "shaders.hpp"
|
||||||
#include "simulation.hpp"
|
#include "simulation.hpp"
|
||||||
|
|
||||||
unsigned short screen_width;
|
|
||||||
unsigned short screen_height;
|
|
||||||
|
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
GLuint program_id;
|
GLuint program_id;
|
||||||
GLuint matrix_id;
|
GLuint matrix_id;
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main() {
|
||||||
// handle arguments
|
|
||||||
struct args args = { 0, 800, 600 };
|
|
||||||
|
|
||||||
argp_parse(&argp, argc, argv, 0, 0, &args);
|
|
||||||
|
|
||||||
screen_width = args.width;
|
|
||||||
screen_height = args.height;
|
|
||||||
|
|
||||||
if(SDL_Init(SDL_INIT_VIDEO) < 0)
|
if(SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||||
{
|
{
|
||||||
std::cerr << "ERROR: " << SDL_GetError() << std::endl;
|
std::cerr << "ERROR: " << SDL_GetError() << std::endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup SDL2 window
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
|
||||||
SDL_GL_CONTEXT_PROFILE_CORE);
|
SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
window = SDL_CreateWindow("Trippy Cube",
|
window = SDL_CreateWindow("Trippy Cube",
|
||||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||||
args.width, args.height,
|
SCREEN_WIDTH, SCREEN_HEIGHT,
|
||||||
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
|
SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
|
||||||
|
|
||||||
if(not window)
|
if(not window)
|
||||||
@ -72,9 +59,7 @@ int main(int argc, char *argv[]) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args.fullscreen)
|
//SDL_ShowCursor(SDL_DISABLE);
|
||||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
|
||||||
|
|
||||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
SDL_GLContext glcontext = SDL_GL_CreateContext(window);
|
SDL_GLContext glcontext = SDL_GL_CreateContext(window);
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.hpp"
|
||||||
#include "input.hpp"
|
#include "input.hpp"
|
||||||
#include "camera.hpp"
|
#include "camera.hpp"
|
||||||
#include "cube.hpp"
|
#include "cube.hpp"
|
||||||
@ -39,11 +39,8 @@ void run() {
|
|||||||
camera cam;
|
camera cam;
|
||||||
cube box;
|
cube box;
|
||||||
|
|
||||||
unsigned int last_time = SDL_GetTicks();
|
|
||||||
|
|
||||||
while(not in_sys.get_action("quit"))
|
while(not in_sys.get_action("quit"))
|
||||||
{
|
{
|
||||||
in_sys.sync_events();
|
|
||||||
cam.update(&in_sys);
|
cam.update(&in_sys);
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
@ -52,7 +49,7 @@ void run() {
|
|||||||
glm::mat4 mvp;
|
glm::mat4 mvp;
|
||||||
{
|
{
|
||||||
glm::mat4 proj = glm::perspective(glm::radians(45.0f),
|
glm::mat4 proj = glm::perspective(glm::radians(45.0f),
|
||||||
static_cast<float>(screen_width) / static_cast<float>(screen_height),
|
static_cast<float>(SCREEN_WIDTH) / static_cast<float>(SCREEN_HEIGHT),
|
||||||
0.1f, 100.0f);
|
0.1f, 100.0f);
|
||||||
|
|
||||||
glm::mat4 view = glm::lookAt(
|
glm::mat4 view = glm::lookAt(
|
||||||
@ -67,10 +64,9 @@ void run() {
|
|||||||
glUniformMatrix4fv(matrix_id, 1, GL_FALSE, &mvp[0][0]);
|
glUniformMatrix4fv(matrix_id, 1, GL_FALSE, &mvp[0][0]);
|
||||||
|
|
||||||
box.render();
|
box.render();
|
||||||
|
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
|
|
||||||
if(SDL_GetTicks() - last_time < (1000 / 60))
|
in_sys.sync_events();
|
||||||
SDL_Delay((1000 / 60) - (SDL_GetTicks() - last_time));
|
|
||||||
last_time = SDL_GetTicks();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user