-
Notifications
You must be signed in to change notification settings - Fork 1
/
bg.c
executable file
·93 lines (80 loc) · 2.4 KB
/
bg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "bg.h"
#include "config.h"
#include "sdl_ogl.h"
#include "location.h"
static const GLfloat BG_SIZE = 7.0;
static struct texture *bg_clear_texture = NULL;
static struct texture *bg_texture = NULL;
static GLfloat angle_step = 0;
static GLfloat angle = 0;
static GLfloat alpha = 1.0;
void bg_clear( void ) {
bg_texture = bg_clear_texture;
}
int bg_init( void ) {
const struct config *config = config_get();
char filename[CONFIG_FILE_NAME_LENGTH];
if( config->iface.theme.background_image[0] != '\0' ) {
location_get_theme_path( config->iface.theme.background_image , filename );
bg_clear_texture = sdl_create_texture( filename );
if( bg_clear_texture == NULL ) {
fprintf( stderr, "Warning: couldn't create background texture from '%s'\n", config->iface.theme.background_image );
return -1;
}
}
alpha = 1.0 - (GLfloat)(config->iface.theme.background_transparency)/100;
if( config->iface.frame_rate )
angle_step = (GLfloat)config->iface.theme.background_rotation/((GLfloat)config->iface.frame_rate*20);
else
angle_step = (GLfloat)config->iface.theme.background_rotation/1000;
bg_clear();
return 0;
}
void bg_free( void ) {
if( bg_texture != bg_clear_texture ) {
ogl_free_texture( bg_clear_texture );
}
ogl_free_texture( bg_texture );
}
void bg_pause( void ) {
bg_free();
}
int bg_resume( void ) {
return bg_init();
}
int bg_set( const char *filename ) {
if( filename && *filename ) {
if( bg_texture != bg_clear_texture ) {
ogl_free_texture( bg_texture );
}
bg_texture = sdl_create_texture( filename );
if( bg_texture == 0 ) {
fprintf( stderr, "Warning: couldn't load background image '%s'\n", filename );
return -1;
}
}
else {
bg_clear();
}
return 0;
}
void bg_draw( void ) {
if( bg_texture ) {
ogl_load_alterego();
glEnable( GL_TEXTURE_2D );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glBindTexture( GL_TEXTURE_2D, bg_texture->id );
glColor4f( 1.0, 1.0, 1.0, alpha );
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glRotatef( angle, 0.0, 0.0, 1.0 );
glTranslatef( 0.0, 0.0, -10.0 );
glBegin( GL_QUADS );
glTexCoord2f(0.0, 0.0); glVertex3f( -BG_SIZE, BG_SIZE, 0.0 );
glTexCoord2f(0.0, 1.0); glVertex3f( -BG_SIZE, -BG_SIZE, 0.0 );
glTexCoord2f(1.0, 1.0); glVertex3f( BG_SIZE, -BG_SIZE, 0.0 );
glTexCoord2f(1.0, 0.0); glVertex3f( BG_SIZE, BG_SIZE, 0.0 );
glEnd();
glDisable( GL_TEXTURE_2D );
angle -= angle_step;
}
}