create Mode interface, move default mode into FadingLogosMode class
This commit is contained in:
parent
c3a3379b56
commit
df8a599d8e
57
src/fading_logos_mode.d
Normal file
57
src/fading_logos_mode.d
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import derelict.opengl3.gl3;
|
||||||
|
import gl3n.linalg;
|
||||||
|
|
||||||
|
static import logo;
|
||||||
|
import screensaver;
|
||||||
|
import mode;
|
||||||
|
import default_shader;
|
||||||
|
|
||||||
|
class FadingLogosMode : Mode
|
||||||
|
{
|
||||||
|
DefaultShader m_shader;
|
||||||
|
|
||||||
|
public void init(ScreenSaver ss)
|
||||||
|
{
|
||||||
|
glClearColor (0.0, 0.0, 0.0, 0.0);
|
||||||
|
glViewport(0, 0, ss.get_width(), ss.get_height());
|
||||||
|
m_shader = new DefaultShader();
|
||||||
|
m_shader.bind();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void display(ScreenSaver ss, int ms)
|
||||||
|
{
|
||||||
|
mat4 view_matrix;
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
view_matrix.make_identity();
|
||||||
|
view_matrix.scale(ss.get_height() / cast(float)ss.get_width(), 1.0, 1.0);
|
||||||
|
double scale = 0.35 * ss.get_width() * 1080.0 / (ss.get_height() * 1920.0);
|
||||||
|
view_matrix.scale(scale, scale, scale);
|
||||||
|
|
||||||
|
glUniformMatrix4fv(m_shader.view_idx, 1, GL_TRUE, view_matrix.value_ptr);
|
||||||
|
|
||||||
|
for (int i = 0; i < N_GENTEX; i++)
|
||||||
|
{
|
||||||
|
draw_letter(logo.GENTEX, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < N_CORPORATION; i++)
|
||||||
|
{
|
||||||
|
draw_letter(logo.CORPORATION, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void draw_letter(int word, int character)
|
||||||
|
{
|
||||||
|
float color[] =
|
||||||
|
(word == logo.GENTEX)
|
||||||
|
? [0.0, 93.0/255.0, 171.0/255.0]
|
||||||
|
: [187.0/255.0, 188.0/255.0, 190.0/255.0];
|
||||||
|
glUniform3fv(m_shader.color_idx, 1, color.ptr);
|
||||||
|
logo.draw(logo.FACE, word, character, m_shader.position_idx);
|
||||||
|
|
||||||
|
color = [1.0, 1.0, 1.0];
|
||||||
|
glUniform3fv(m_shader.color_idx, 1, color.ptr);
|
||||||
|
logo.draw(logo.WIRE, word, character, m_shader.position_idx);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,7 @@
|
|||||||
import screensaver;
|
import screensaver;
|
||||||
|
import mode;
|
||||||
|
|
||||||
|
import fading_logos_mode;
|
||||||
|
|
||||||
extern(C) void GetDisplaySize(int * width, int * height, int * num_monitors);
|
extern(C) void GetDisplaySize(int * width, int * height, int * num_monitors);
|
||||||
|
|
||||||
@ -11,7 +14,10 @@ int main()
|
|||||||
width = 1920 * 2; /* restrict to two monitors */
|
width = 1920 * 2; /* restrict to two monitors */
|
||||||
|
|
||||||
ScreenSaver ss = new ScreenSaver(width, height);
|
ScreenSaver ss = new ScreenSaver(width, height);
|
||||||
ss.run();
|
Mode modes[] = [
|
||||||
|
new FadingLogosMode(),
|
||||||
|
];
|
||||||
|
ss.run(modes);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
16
src/mode.d
Normal file
16
src/mode.d
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import screensaver;
|
||||||
|
|
||||||
|
interface Mode
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Initialize the ScreenSaver mode.
|
||||||
|
*/
|
||||||
|
public void init(ScreenSaver ss);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw the screen.
|
||||||
|
*
|
||||||
|
* @param[in] ms Elapsed milliseconds since this mode was started.
|
||||||
|
*/
|
||||||
|
public void display(ScreenSaver ss, int ms);
|
||||||
|
}
|
@ -3,10 +3,9 @@ import derelict.sdl2.sdl;
|
|||||||
import derelict.opengl3.gl3;
|
import derelict.opengl3.gl3;
|
||||||
import glamour.vao;
|
import glamour.vao;
|
||||||
import glamour.vbo;
|
import glamour.vbo;
|
||||||
import gl3n.linalg;
|
|
||||||
|
|
||||||
static import logo;
|
static import logo;
|
||||||
import default_shader;
|
import mode;
|
||||||
|
|
||||||
immutable int N_GENTEX = 6;
|
immutable int N_GENTEX = 6;
|
||||||
immutable int N_CORPORATION = 11;
|
immutable int N_CORPORATION = 11;
|
||||||
@ -17,54 +16,6 @@ class ScreenSaver
|
|||||||
protected int m_height;
|
protected int m_height;
|
||||||
protected SDL_Window * m_window;
|
protected SDL_Window * m_window;
|
||||||
protected SDL_GLContext m_context;
|
protected SDL_GLContext m_context;
|
||||||
DefaultShader m_shader;
|
|
||||||
|
|
||||||
protected void init()
|
|
||||||
{
|
|
||||||
glClearColor (0.0, 0.0, 0.0, 0.0);
|
|
||||||
glViewport(0, 0, m_width, m_height);
|
|
||||||
m_shader = new DefaultShader();
|
|
||||||
m_shader.bind();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void draw_letter(int word, int character)
|
|
||||||
{
|
|
||||||
float color[] =
|
|
||||||
(word == logo.GENTEX)
|
|
||||||
? [0.0, 93.0/255.0, 171.0/255.0]
|
|
||||||
: [187.0/255.0, 188.0/255.0, 190.0/255.0];
|
|
||||||
glUniform3fv(m_shader.color_idx, 1, color.ptr);
|
|
||||||
logo.draw(logo.FACE, word, character, m_shader.position_idx);
|
|
||||||
|
|
||||||
color = [1.0, 1.0, 1.0];
|
|
||||||
glUniform3fv(m_shader.color_idx, 1, color.ptr);
|
|
||||||
logo.draw(logo.WIRE, word, character, m_shader.position_idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void display()
|
|
||||||
{
|
|
||||||
mat4 view_matrix;
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
|
|
||||||
view_matrix.make_identity();
|
|
||||||
view_matrix.scale(m_height / cast(float)m_width, 1.0, 1.0);
|
|
||||||
double scale = 0.35 * m_width * 1080.0 / (m_height * 1920.0);
|
|
||||||
view_matrix.scale(scale, scale, scale);
|
|
||||||
|
|
||||||
glUniformMatrix4fv(m_shader.view_idx, 1, GL_TRUE, view_matrix.value_ptr);
|
|
||||||
|
|
||||||
for (int i = 0; i < N_GENTEX; i++)
|
|
||||||
{
|
|
||||||
draw_letter(logo.GENTEX, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < N_CORPORATION; i++)
|
|
||||||
{
|
|
||||||
draw_letter(logo.CORPORATION, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_GL_SwapWindow(m_window);
|
|
||||||
}
|
|
||||||
|
|
||||||
this(int width, int height)
|
this(int width, int height)
|
||||||
{
|
{
|
||||||
@ -106,9 +57,9 @@ class ScreenSaver
|
|||||||
logo.init();
|
logo.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void run()
|
public void run(Mode modes[])
|
||||||
{
|
{
|
||||||
init();
|
modes[0].init(this);
|
||||||
|
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
for (;;)
|
for (;;)
|
||||||
@ -118,7 +69,8 @@ class ScreenSaver
|
|||||||
if ((event.type == SDL_QUIT) || (event.type == SDL_KEYDOWN))
|
if ((event.type == SDL_QUIT) || (event.type == SDL_KEYDOWN))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
display();
|
modes[0].display(this, SDL_GetTicks());
|
||||||
|
SDL_GL_SwapWindow(m_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_DeleteContext(m_context);
|
SDL_GL_DeleteContext(m_context);
|
||||||
@ -127,4 +79,14 @@ class ScreenSaver
|
|||||||
|
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int get_width()
|
||||||
|
{
|
||||||
|
return m_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int get_height()
|
||||||
|
{
|
||||||
|
return m_height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user