Initial commit

This commit is contained in:
captain4lk 2020-04-11 17:03:26 +02:00
parent aff7704b78
commit c65988dd8b
37 changed files with 999 additions and 783 deletions

View file

@ -26,5 +26,4 @@ You need to link your programm to the following libraries:
SLK has been tested on the following plattforms/os:
* Windows (64 and 32 bit)
* Linux (Debian(ARM and 64 bit))
* Linux

View file

@ -1,5 +0,0 @@
# TODO list of SLK-Engine:
* rename INBOUNDS TO SLK_INBOUNDS
* rename SIGNUM TO SLK_SIGNUM
* rename SWAP to SLK_SWAP

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 4 KiB

View file

@ -1,8 +0,0 @@
**This file contains the sources for the used assets**
* [font](https://opengameart.org/content/superpowers-assets-bitmap-fonts)
* [DinoSprites - doux.png](https://arks.itch.io/dino-characters)
* [DinoSprites - mort.png](https://arks.itch.io/dino-characters)
* [DinoSprites - tard.png](https://arks.itch.io/dino-characters)
* [DinoSprites - vita.png](https://arks.itch.io/dino-characters)
* Logo.png: C4LK (the author)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,42 @@
JASC-PAL
0100
39
0 0 0
33 48 56
67 125 160
77 146 188
154 40 144
255 255 255
216 183 143
255 215 168
56 33 33
160 67 69
188 77 79
75 154 39
74 59 31
229 171 61
253 199 96
35 121 234
0 148 255
50 56 33
136 160 67
159 188 77
196 63 49
5 4 3
27 36 71
61 111 67
97 165 63
143 208 50
23 21 22
103 57 49
180 117 56
192 144 169
189 164 153
201 212 253
128 123 122
211 151 65
248 197 58
248 246 68
181 231 203
66 191 232
39 137 205

View file

@ -0,0 +1,20 @@
JASC-PAL
0100
17
0 0 0
0 0 0
255 255 255
247 226 107
163 206 39
68 137 26
49 162 242
178 220 239
0 87 132
224 111 139
190 38 51
164 100 34
235 137 49
157 157 157
47 72 78
73 60 43
27 38 50

BIN
examples/assets/tetris.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

BIN
examples/assets/tetris.slk Normal file

Binary file not shown.

View file

@ -4,5 +4,6 @@ cd "$(dirname "$0")"
gcc -O3 -o engine main.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
chmod +x engine
./engine
exit
/bin/bash

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

View file

@ -0,0 +1,20 @@
JASC-PAL
0100
17
0 0 0
69 36 52
20 12 28
211 170 154
223 239 215
211 125 44
219 215 93
211 69 73
134 77 48
77 73 77
48 52 109
117 113 97
109 195 203
134 150 162
109 170 44
52 101 36
89 125 207

View file

@ -6,6 +6,7 @@ typedef struct
int y;
int type;
int frame;
int flip;
}Dino;
typedef struct
@ -16,7 +17,7 @@ typedef struct
}Dino_army;
Dino_army world;
SLK_Sprite_rgb *dino_sprites[4][24];
SLK_Sprite *dino_sprites[4][24];
int frame = 0;
char time_stat[48];
@ -24,63 +25,61 @@ void add_dino();
int main(int argc, char *argv[])
{
SLK_setup(256,224,"SLK Engine",0,3);
SLK_setup(320,240,"SLK Engine",1,1);
SLK_set_FPS(30);
SLK_show_cursor(1);
SLK_set_clear_color(SLK_create_color(0,0,0,255));
SLK_set_clear_color(1);
SLK_clear_screen();
srand(time(NULL));
SLK_Sprite_rgb *tileset = SLK_load_sprite_rgb("../assets/DinoSprites - doux.png");
SLK_load_palette("../assets/performance.pal");
SLK_Sprite *tileset = SLK_load_sprite("../assets/dino_sprites_doux.slk");
for(int x = 0;x<24;x++)
{
dino_sprites[0][x] = SLK_create_sprite_rgb(24,24);
SLK_set_draw_target(dino_sprites[0][x]);
SLK_draw_partial_sprite_rgb(tileset,0,0,x*24,0,24,24);
dino_sprites[0][x] = SLK_create_sprite(24,24);
SLK_copy_partial_sprite(dino_sprites[0][x],tileset,0,0,x*24,0,24,24);
}
SLK_destroy_sprite_rgb(tileset);
SLK_destroy_sprite(tileset);
tileset = SLK_load_sprite_rgb("../assets/DinoSprites - mort.png");
tileset = SLK_load_sprite("../assets/dino_sprites_mort.slk");
for(int x = 0;x<24;x++)
{
dino_sprites[1][x] = SLK_create_sprite_rgb(24,24);
SLK_set_draw_target(dino_sprites[1][x]);
SLK_draw_partial_sprite_rgb(tileset,0,0,x*24,0,24,24);
dino_sprites[1][x] = SLK_create_sprite(24,24);
SLK_copy_partial_sprite(dino_sprites[1][x],tileset,0,0,x*24,0,24,24);
}
SLK_destroy_sprite_rgb(tileset);
SLK_destroy_sprite(tileset);
tileset = SLK_load_sprite_rgb("../assets/DinoSprites - tard.png");
tileset = SLK_load_sprite("../assets/dino_sprites_tard.slk");
for(int x = 0;x<24;x++)
{
dino_sprites[2][x] = SLK_create_sprite_rgb(24,24);
SLK_set_draw_target(dino_sprites[2][x]);
SLK_draw_partial_sprite_rgb(tileset,0,0,x*24,0,24,24);
dino_sprites[2][x] = SLK_create_sprite(24,24);
SLK_copy_partial_sprite(dino_sprites[2][x],tileset,0,0,x*24,0,24,24);
}
SLK_destroy_sprite_rgb(tileset);
SLK_destroy_sprite(tileset);
tileset = SLK_load_sprite_rgb("../assets/DinoSprites - vita.png");
tileset = SLK_load_sprite("../assets/dino_sprites_vita.slk");
for(int x = 0;x<24;x++)
{
dino_sprites[3][x] = SLK_create_sprite_rgb(24,24);
SLK_set_draw_target(dino_sprites[3][x]);
SLK_draw_partial_sprite_rgb(tileset,0,0,x*24,0,24,24);
dino_sprites[3][x] = SLK_create_sprite(24,24);
SLK_copy_partial_sprite(dino_sprites[3][x],tileset,0,0,x*24,0,24,24);
}
SLK_destroy_sprite_rgb(tileset);
SLK_set_draw_target(NULL);
SLK_destroy_sprite(tileset);
world.space = 100;
world.used = 0;
world.dinos = malloc(sizeof(Dino)*world.space);
clock_t end = 0;
double time = 0;
while(world.used<1000)
add_dino();
while(SLK_running())
{
SLK_update();
SLK_clear_screen();
frame++;
int next_frame = frame%5==0;
int next_frame = frame%4==0;
clock_t start = clock();
for(int i = 0;i<world.used;i++)
@ -91,21 +90,18 @@ int main(int argc, char *argv[])
if(world.dinos[i].frame>3)
world.dinos[i].frame = 0;
}
SLK_draw_sprite_rgb(dino_sprites[world.dinos[i].type][world.dinos[i].frame],world.dinos[i].x,world.dinos[i].y);
SLK_draw_sprite(dino_sprites[world.dinos[i].type][world.dinos[i].frame],world.dinos[i].x,world.dinos[i].y);
}
time+=((double)(clock()-start)/CLOCKS_PER_SEC);
if(next_frame)
sprintf(time_stat,"%04lf %04d",time/((double)frame)/*/world.used*10.0f*/,world.used);
if(SLK_key_down(SLK_KEY_SPACE)||world.used<1000)
if(SLK_key_down(SLK_KEY_SPACE))
add_dino();
if(SLK_key_pressed(SLK_KEY_D))
{
end = 1;
frame = 1;
}
end += clock()-start;
sprintf(time_stat,"%04ld %04d",end/frame,world.used);
SLK_draw_string(0,0,1,time_stat,SLK_create_color(255,255,255,255));
SLK_fill_rectangle(0,0,104,8,SLK_create_paxel(2,SLK_OPAQUE));
SLK_draw_string(0,0,1,time_stat,SLK_create_paxel(3,SLK_OPAQUE));
SLK_update_screen();
}
@ -116,9 +112,10 @@ int main(int argc, char *argv[])
void add_dino()
{
world.dinos[world.used].frame = rand()%4;
world.dinos[world.used].x = rand()%256-12;
world.dinos[world.used].y = rand()%224-12;
world.dinos[world.used].x = rand()%320-12;
world.dinos[world.used].y = rand()%240-12;
world.dinos[world.used].type = rand()%4;
world.dinos[world.used].flip = rand()%2;
world.used++;

View file

@ -1,8 +1,8 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o engine main.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
chmod +x engine
./engine
gcc -O3 -o voxelspace *.c ../../lib/libSLK.a -lm -lSDL2 -lGL -lpng -lz -Wall
chmod +x voxelspace
./voxelspace
/bin/bash

9
examples/tetris/build_linux.sh Executable file
View file

@ -0,0 +1,9 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -o engine *.c ../../lib/libSLK.a -lm -lSDL2 -lGL -Wall
chmod +x engine
./engine
exit
/bin/bash

Binary file not shown.

View file

@ -0,0 +1,20 @@
JASC-PAL
0100
17
0 0 0
69 36 52
20 12 28
211 170 154
223 239 215
211 125 44
219 215 93
211 69 73
134 77 48
77 73 77
48 52 109
117 113 97
109 195 203
134 150 162
109 170 44
52 101 36
89 125 207

73
examples/tetris/main.c Normal file
View file

@ -0,0 +1,73 @@
#include "../../include/SLK/SLK.h"
void update_menu();
SLK_Sprite *sprites_blocks[26];
int mode = 0;
int game_mode_left = 0;
int game_mode_right = 0;
int main(int argc, char *argv[])
{
SLK_setup(323,240,"Tetris",1,0);
SLK_set_FPS(30);
SLK_show_cursor(1);
SLK_set_clear_color(0);
SLK_clear_screen();
SLK_load_palette("../assets/tetris.pal");
SLK_Sprite *tileset = SLK_load_sprite("../assets/tetris.slk");
for(int x = 0;x<26;x++)
{
sprites_blocks[x] = SLK_create_sprite(16,16);
SLK_copy_partial_sprite(sprites_blocks[x],tileset,0,0,x*16,0,16,16);
}
SLK_destroy_sprite(tileset);
while(SLK_running())
{
SLK_update();
switch(mode)
{
case 0:
update_menu();
break;
}
SLK_update_screen();
}
return 0;
}
void update_menu()
{
if(game_mode_left==0)
{
SLK_draw_string(10,80,3,"T",SLK_create_paxel(10,SLK_OPAQUE));
SLK_draw_string(26,80,3,"e",SLK_create_paxel(12,SLK_OPAQUE));
SLK_draw_string(42,80,3,"t",SLK_create_paxel(3,SLK_OPAQUE));
SLK_draw_string(58,80,3,"r",SLK_create_paxel(4,SLK_OPAQUE));
SLK_draw_string(74,80,3,"i",SLK_create_paxel(6,SLK_OPAQUE));
SLK_draw_string(90,80,3,"s",SLK_create_paxel(9,SLK_OPAQUE));
}
else
{
}
if(game_mode_right==0)
{
}
else
{
}
SLK_draw_rectangle(0,0,162,240,SLK_create_paxel(2,SLK_OPAQUE));
SLK_draw_rectangle(161,0,162,240,SLK_create_paxel(2,SLK_OPAQUE));
//SLK_draw_line(162,0,162,240,SLK_create_paxel(3,SLK_OPAQUE));
}

View file

@ -23,45 +23,39 @@
#define _SLK_FUNCTIONS_H_
//SLK_Sprite functionality
SLK_Sprite_pal *SLK_create_sprite_pal(int width, int height);
SLK_Sprite_rgb *SLK_create_sprite_rgb(int width, int height);
void SLK_destroy_sprite_pal(SLK_Sprite_pal *s);
void SLK_destroy_sprite_rgb(SLK_Sprite_rgb *s);
uint8 SLK_get_pixel_pal(SLK_Sprite_pal *s, int x, int y);
SLK_Color SLK_get_pixel_rgb(SLK_Sprite_rgb *s, int x, int y);
void SLK_set_pixel_pal(SLK_Sprite_pal *s, int x, int y, uint8 c);
void SLK_set_pixel_rgb(SLK_Sprite_rgb *s, int x, int y, SLK_Color c);
void SLK_set_palette(SLK_Sprite_pal *s, SLK_Palette *p);
SLK_Palette *SLK_get_palette(SLK_Sprite_pal *s);
SLK_Sprite_pal *SLK_sprite_rgb_to_pal(SLK_Sprite_rgb *s);
SLK_Sprite_rgb *SLK_sprite_pal_to_rgb(SLK_Sprite_pal *s);
SLK_Sprite_rgb *SLK_load_sprite_rgb(const char *path);
void SLK_save_sprite_rgb(const char *path, SLK_Sprite_rgb *s);
SLK_Sprite *SLK_create_sprite(int width, int height);
void SLK_destroy_sprite(SLK_Sprite *s);
SLK_Paxel SLK_get_paxel(SLK_Sprite *s, int x, int y);
void SLK_set_paxel(SLK_Sprite *s, int x, int y, SLK_Paxel c);
SLK_Sprite *SLK_load_sprite(const char *path);
void SLK_save_sprite(const char *path, SLK_Sprite *s);
//--------------------------------------------
//SLK_Palette functionality
SLK_Palette *SLK_create_palette();
void SLK_destroy_palette(SLK_Palette *p);
void SLK_set_palette_color(SLK_Palette *p, uint8 index, SLK_Color c);
SLK_Color SLK_get_palette_color(SLK_Palette *p, uint8 index);
void SLK_load_palette(const char *path);
//--------------------------------------------
//SLK_draw functionality
void SLK_draw_sprite_pal(SLK_Sprite_pal *s, int x, int y);
void SLK_draw_sprite_rgb(SLK_Sprite_rgb *s, int x, int y);
void SLK_draw_sprite_flip_rgb(SLK_Sprite_rgb *s, int x, int y, int flip);
void SLK_draw_rectangle(int x, int y, int width, int height, SLK_Color c);
void SLK_fill_rectangle(int x, int y, int width, int height, SLK_Color c);
void SLK_draw_line(int x1, int y1, int x2, int y2, SLK_Color c);
void SLK_draw(int x, int y, SLK_Color c);
void SLK_draw_nc(int x, int y, SLK_Color c);
void SLK_draw_string(int x, int y, int scale, const char *text, SLK_Color c);
void SLK_draw_partial_sprite_rgb(SLK_Sprite_rgb *s, int x, int y, int ox, int oy, int width, int height);
void SLK_draw(int x, int y, SLK_Paxel p);
void SLK_draw_nc(int x, int y, SLK_Paxel p);
void SLK_draw_string(int x, int y, int scale, const char *text, SLK_Paxel p);
void SLK_draw_sprite(const SLK_Sprite *s, const int x, const int y);
void SLK_draw_sprite_partial(SLK_Sprite *s, int x, int y, int ox, int oy, int width, int height);
void SLK_draw_sprite_flip(const SLK_Sprite *s, const int x, const int y, const int flip);
void SLK_draw_line(int x1, int y1, int x2, int y2, SLK_Paxel p);
void SLK_draw_vertical_line(int x, int y1, int y2, SLK_Paxel p);
void SLK_draw_rectangle(int x, int y, int width, int height, SLK_Paxel p);
void SLK_fill_rectangle(int x, int y, int width, int height, SLK_Paxel p);
void SLK_clear_screen();
//--------------------------------------------
//SLK_copy functionality
void SLK_copy_partial_sprite(SLK_Sprite *dst, SLK_Sprite *src, int x, int y, int ox, int oy, int width, int height);
//--------------------------------------------
//SLK_color functionality
SLK_Color SLK_create_color(uint8 r, uint8 g, uint8 b, uint8 a);
SLK_Paxel SLK_create_paxel(uint8_t index, uint8_t mask);
//--------------------------------------------
//SLK_input functionality
@ -72,10 +66,12 @@ int SLK_mouse_down(int key);
int SLK_mouse_pressed(int key);
int SLK_mouse_released(int key);
void SLK_get_mouse_pos(int *x, int *y);
void SLK_start_text_input(char *text);
void SLK_stop_text_input();
//--------------------------------------------
//SLK_core functionality
void SLK_set_clear_color(SLK_Color c);
void SLK_set_clear_color(int index);
void SLK_setup(int width, int height, const char *title, int fullscreen, int pixel_scale);
void SLK_end();
void SLK_update();
@ -86,7 +82,9 @@ void SLK_set_FPS(int FPS);
void SLK_show_cursor(int shown);
int SLK_running();
void SLK_quit();
void SLK_set_draw_target(SLK_Sprite_rgb *target);
void SLK_set_draw_target(SLK_Sprite *new_target);
void SLK_start_timer();
void SLK_end_timer();
//--------------------------------------------
#endif //_SLK_FUNCTIONS_H_

View file

@ -37,32 +37,29 @@ typedef double float64;
typedef struct
{
union
{
uint32 n;
struct
{
uint8 r;
uint8 g;
uint8 b;
uint8 a;
};
};
union
{
uint32 n;
struct
{
uint8 r;
uint8 g;
uint8 b;
uint8 a;
};
};
}SLK_Color;
typedef struct
{
SLK_Color colors[256];
uint8 used;
}SLK_Palette;
uint8_t index;
uint8_t mask;
}SLK_Paxel;
typedef struct
{
int width;
int height;
uint8 *data;
SLK_Palette *palette;
}SLK_Sprite_pal;
SLK_Color colors[256];
}SLK_Palette;
typedef struct
{
@ -71,6 +68,13 @@ typedef struct
SLK_Color *data;
}SLK_Sprite_rgb;
typedef struct
{
int width;
int height;
SLK_Paxel *data;
}SLK_Sprite;
typedef struct
{
uint8 pressed;
@ -102,4 +106,10 @@ enum SLK_mouse_button
SLK_BUTTON_LEFT,SLK_BUTTON_RIGHT,SLK_BUTTON_MIDDLE,SLK_BUTTON_X1,SLK_BUTTON_X2,
};
enum SLK_mask
{
SLK_OPAQUE = 0,
SLK_TRANSPARENT = 255,
};
#endif //_4LK_TYPES_H_

View file

@ -5,7 +5,7 @@ SRC = $(wildcard ../src/*.c)
OBJ = $(patsubst %.c,%.o,$(SRC))
%.o: ../src/%.c $(DEPS)
$(CC) -O3 -c $< -lm -lSDL2 -lGL -lpng -lz -Wall
$(CC) -O2 -S $< -lm -lSDL2 -lGL -Wall
libSLK.a: $(OBJ)
ar cr libSLK.a *.o

View file

@ -1,7 +1,8 @@
#!/bin/bash
cd "$(dirname "$0")"
gcc -O3 -c ../src/*.c -lm -lSDL2 -lGL -lpng -lz -Wall
gcc -O3 -c ../src/*.c -lm -lSDL2 -lGL -Wall -fvisibility=hidden
ar cr libSLK.a *.o
exit
/bin/bash

34
src/SLK_copy.c Normal file
View file

@ -0,0 +1,34 @@
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
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.
*/
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
void SLK_copy_partial_sprite(SLK_Sprite *dst, SLK_Sprite *src, int x, int y, int ox, int oy, int width, int height)
{
for(int tx = 0; tx < width; tx++)
{
for(int ty = 0; ty < height; ty++)
{
SLK_Paxel c = SLK_get_paxel(src, tx + ox, ty + oy);
SLK_set_paxel(dst,x + tx, y +ty, c);
}
}
}

View file

@ -1,392 +1,414 @@
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
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.
*/
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
void SLK_set_FPS(int FPS)
{
engine->FPS = FPS;
engine->frame_delay = 1000/engine->FPS;
}
void SLK_quit()
{
engine->running = 0;
}
int SLK_running()
{
return engine->running;
}
SLK_Color SLK_create_color(uint8 r, uint8 g, uint8 b, uint8 a)
{
SLK_Color c;
c.r = r;
c.g = g;
c.b = b;
c.a = a;
return c;
}
void SLK_set_clear_color(SLK_Color c)
{
engine->clear_color = c;
}
void SLK_show_cursor(int shown)
{
SDL_ShowCursor(shown?SDL_ENABLE:SDL_DISABLE);
}
void SLK_update_screen()
{
glViewport(engine->view_x,engine->view_y,engine->view_width,engine->view_height);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,engine->screen_width,engine->screen_height,GL_RGBA,GL_UNSIGNED_BYTE,engine->default_draw_target->data);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0f,-1.0f,0.0f);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0f,1.0f,0.0f);
glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0f,1.0f,0.0f);
glTexCoord2f(1.0,1.0);
glVertex3f(1.0f,-1.0f,0.0f);
glEnd();
//glFinish();
SDL_GL_SwapWindow(engine->sdl_window);
}
void SLK_update()
{
engine->frametime = SDL_GetTicks()-engine->framestart;
if(engine->frame_delay>engine->frametime)
SDL_Delay(engine->frame_delay-engine->frametime);
engine->gone_fps++;
engine->framestart = SDL_GetTicks();
//Event managing, done
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
engine->running = 0;
break;
case SDL_MOUSEMOTION:
SLK_update_mouse(event.motion.x,event.motion.y);
break;
case SDL_KEYDOWN:
if(event.key.state==SDL_PRESSED)
engine->new_key_state[engine->key_map[event.key.keysym.scancode]] = 1;
break;
case SDL_KEYUP:
if(event.key.state==SDL_RELEASED)
engine->new_key_state[engine->key_map[event.key.keysym.scancode]] = 0;
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.state==SDL_PRESSED)
engine->new_mouse_state[engine->mouse_map[event.button.button]] = 1;
break;
case SDL_MOUSEBUTTONUP:
if(event.button.state==SDL_RELEASED)
engine->new_mouse_state[engine->mouse_map[event.button.button]] = 0;
break;
}
}
//-------------------------------------------
for(int i = 0; i<256; i++)
{
engine->keyboard_state[i].released = 0;
engine->keyboard_state[i].pressed = 0;
if(engine->new_key_state[i]!=engine->old_key_state[i])
{
if(engine->new_key_state[i])
{
engine->keyboard_state[i].pressed = !engine->keyboard_state[i].held;
engine->keyboard_state[i].held = 1;
}
else
{
engine->keyboard_state[i].released = 1;
engine->keyboard_state[i].held = 0;
}
}
engine->old_key_state[i] = engine->new_key_state[i];
}
for(int i = 0;i<6;i++)
{
engine->mouse_state[i].pressed = 0;
engine->mouse_state[i].released = 0;
if(engine->new_mouse_state[i]!=engine->old_mouse_state[i])
{
if(engine->new_mouse_state[i])
{
engine->mouse_state[i].pressed = !engine->mouse_state[i].held;
engine->mouse_state[i].held =1;
}
else
{
engine->mouse_state[i].released = 1;
engine->mouse_state[i].held = 0;
}
}
engine->old_mouse_state[i] = engine->new_mouse_state[i];
}
}
void SLK_update_viewport()
{
int pixel_scale = (int)(floor((float)engine->window_width/(float)engine->screen_width));
engine->view_width = (int)engine->screen_width*pixel_scale;
engine->view_height = (int)engine->screen_height*pixel_scale;
if (engine->view_height>engine->window_height)
{
pixel_scale = (int)(floor((float)engine->window_height/(float)engine->screen_height));
engine->view_width = (int32)engine->screen_width*pixel_scale;
engine->view_height = (int32)engine->screen_height*pixel_scale;
}
engine->view_x = (engine->window_width-engine->view_width)/2;
engine->view_y = (engine->window_height-engine->view_height)/2;
}
void SLK_update_mouse(int x, int y)
{
x-=engine->view_x;
y-=engine->view_y;
engine->mouse_x_cache = (int)(((float)x/(float)(engine->window_width-(engine->view_x*2))*(float)engine->screen_width));
engine->mouse_y_cache = (int)(((float)y/(float)(engine->window_height-(engine->view_y*2))*(float)engine->screen_height));
if(engine->mouse_x_cache>=engine->screen_width)
engine->mouse_x_cache = engine->screen_width-1;
if(engine->mouse_y_cache>=engine->screen_height)
engine->mouse_y_cache = engine->screen_height-1;
if(engine->mouse_x_cache<0)
engine->mouse_x_cache = 0;
if(engine->mouse_y_cache<1)
engine->mouse_y_cache = 1;
}
void SLK_set_draw_target(SLK_Sprite_rgb *target)
{
if(target)
engine->draw_target = target;
else
engine->draw_target = engine->default_draw_target;
}
void SLK_setup(int width, int height, const char *title, int fullscreen, int pixel_scale)
{
engine = NULL;
engine = (SLK_engine *)malloc(sizeof(SLK_engine));
if(!engine)
{
printf("FATAL ERROR: failed to allocate memory for engine!!!\n");
exit(-1);
}
memset(engine,0,sizeof(SLK_engine));
engine->screen_width = width;
engine->screen_height = height;
font_sprite = SLK_load_sprite_rgb("data/font8x8.png");
engine->default_draw_target = SLK_create_sprite_rgb(engine->screen_width,engine->screen_height);
SLK_set_draw_target(NULL);
if(SDL_Init(SDL_INIT_EVERYTHING)<0)
{
printf("FATAL ERROR: failed to init sdl\n");
exit(-1);
}
SDL_GL_LoadLibrary(NULL);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,1);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
if(fullscreen)
engine->sdl_window = SDL_CreateWindow(title,SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,0,0,SDL_WINDOW_FULLSCREEN_DESKTOP|SDL_WINDOW_OPENGL);
else
engine->sdl_window = SDL_CreateWindow(title,SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,width*pixel_scale,height*pixel_scale,SDL_WINDOW_OPENGL);
if(!engine->sdl_window)
{
printf("FATAL ERROR: failed to create window\n");
exit(-1);
}
engine->sdl_gl_context = SDL_GL_CreateContext(engine->sdl_window);
if(!engine->sdl_gl_context)
{
printf("FATAL ERROR: failed to create opengl context\n");
exit(-1);
}
SDL_GL_SetSwapInterval(0);
printf("OpenGL loaded\n");
printf("Vendor: %s\n",glGetString(GL_VENDOR));
printf("Renderer: %s\n",glGetString(GL_RENDERER));
printf("Version: %s\n",glGetString(GL_VERSION));
printf("SDL_GL_GetSwapInterval: %d\nErrors: %s\n",SDL_GL_GetSwapInterval(),SDL_GetError());
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
SDL_GetWindowSize(engine->sdl_window,&engine->window_width,&engine->window_height);
glViewport(0,0,width,height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT);
SLK_update_viewport();
engine->key_map[0x00] = SLK_KEY_NONE;
engine->key_map[SDL_SCANCODE_A] = SLK_KEY_A;
engine->key_map[SDL_SCANCODE_B] = SLK_KEY_B;
engine->key_map[SDL_SCANCODE_C] = SLK_KEY_C;
engine->key_map[SDL_SCANCODE_D] = SLK_KEY_D;
engine->key_map[SDL_SCANCODE_E] = SLK_KEY_E;
engine->key_map[SDL_SCANCODE_F] = SLK_KEY_F;
engine->key_map[SDL_SCANCODE_G] = SLK_KEY_G;
engine->key_map[SDL_SCANCODE_H] = SLK_KEY_H;
engine->key_map[SDL_SCANCODE_I] = SLK_KEY_I;
engine->key_map[SDL_SCANCODE_J] = SLK_KEY_J;
engine->key_map[SDL_SCANCODE_K] = SLK_KEY_K;
engine->key_map[SDL_SCANCODE_L] = SLK_KEY_L;
engine->key_map[SDL_SCANCODE_M] = SLK_KEY_M;
engine->key_map[SDL_SCANCODE_N] = SLK_KEY_N;
engine->key_map[SDL_SCANCODE_O] = SLK_KEY_O;
engine->key_map[SDL_SCANCODE_P] = SLK_KEY_P;
engine->key_map[SDL_SCANCODE_Q] = SLK_KEY_Q;
engine->key_map[SDL_SCANCODE_R] = SLK_KEY_R;
engine->key_map[SDL_SCANCODE_S] = SLK_KEY_S;
engine->key_map[SDL_SCANCODE_T] = SLK_KEY_T;
engine->key_map[SDL_SCANCODE_U] = SLK_KEY_U;
engine->key_map[SDL_SCANCODE_V] = SLK_KEY_V;
engine->key_map[SDL_SCANCODE_W] = SLK_KEY_W;
engine->key_map[SDL_SCANCODE_X] = SLK_KEY_X;
engine->key_map[SDL_SCANCODE_Y] = SLK_KEY_Y;
engine->key_map[SDL_SCANCODE_Z] = SLK_KEY_Z;
engine->key_map[SDL_SCANCODE_F1] = SLK_KEY_F1;
engine->key_map[SDL_SCANCODE_F2] = SLK_KEY_F2;
engine->key_map[SDL_SCANCODE_F3] = SLK_KEY_F3;
engine->key_map[SDL_SCANCODE_F4] = SLK_KEY_F4;
engine->key_map[SDL_SCANCODE_F5] = SLK_KEY_F5;
engine->key_map[SDL_SCANCODE_F6] = SLK_KEY_F6;
engine->key_map[SDL_SCANCODE_F7] = SLK_KEY_F7;
engine->key_map[SDL_SCANCODE_F8] = SLK_KEY_F8;
engine->key_map[SDL_SCANCODE_F9] = SLK_KEY_F9;
engine->key_map[SDL_SCANCODE_F10] = SLK_KEY_F10;
engine->key_map[SDL_SCANCODE_F11] = SLK_KEY_F11;
engine->key_map[SDL_SCANCODE_F12] = SLK_KEY_F12;
engine->key_map[SDL_SCANCODE_DOWN] = SLK_KEY_DOWN;
engine->key_map[SDL_SCANCODE_LEFT] = SLK_KEY_LEFT;
engine->key_map[SDL_SCANCODE_RIGHT] = SLK_KEY_RIGHT;
engine->key_map[SDL_SCANCODE_UP] = SLK_KEY_UP;
engine->key_map[SDL_SCANCODE_RETURN] = SLK_KEY_ENTER;
engine->key_map[SDL_SCANCODE_BACKSPACE] = SLK_KEY_BACK;
engine->key_map[SDL_SCANCODE_ESCAPE] = SLK_KEY_ESCAPE;
engine->key_map[SDL_SCANCODE_TAB] = SLK_KEY_TAB;
engine->key_map[SDL_SCANCODE_LGUI] = SLK_KEY_HOME;
/*engine->key_map[XK_End] = SLK_KEY_END;
engine->key_map[XK_Page_Up] = SLK_KEY_PGUP;
engine->key_map[XK_Page_Down] = SLK_KEY_PGDN;
engine->key_map[XK_Insert] = SLK_KEY_INS;
engine->key_map[XK_Shift_L] = SLK_KEY_SHIFT;
engine->key_map[XK_Shift_R] = SLK_KEY_SHIFT;
engine->key_map[XK_Control_L] = SLK_KEY_CTRL;
engine->key_map[XK_Control_R] = SLK_KEY_CTRL;*/
engine->key_map[SDL_SCANCODE_SPACE] = SLK_KEY_SPACE;
/*engine->key_map[XK_0] = SLK_KEY_K0;
engine->key_map[XK_1] = SLK_KEY_K1;
engine->key_map[XK_2] = SLK_KEY_K2;
engine->key_map[XK_3] = SLK_KEY_K3;
engine->key_map[XK_4] = SLK_KEY_K4;
engine->key_map[XK_5] = SLK_KEY_K5;
engine->key_map[XK_6] = SLK_KEY_K6;
engine->key_map[XK_7] = SLK_KEY_K7;
engine->key_map[XK_8] = SLK_KEY_K8;
engine->key_map[XK_9] = SLK_KEY_K9;
engine->key_map[XK_KP_0] = SLK_KEY_NP0;
engine->key_map[XK_KP_1] = SLK_KEY_NP1;
engine->key_map[XK_KP_2] = SLK_KEY_NP2;
engine->key_map[XK_KP_3] = SLK_KEY_NP3;
engine->key_map[XK_KP_4] = SLK_KEY_NP4;
engine->key_map[XK_KP_5] = SLK_KEY_NP5;
engine->key_map[XK_KP_6] = SLK_KEY_NP6;
engine->key_map[XK_KP_7] = SLK_KEY_NP7;
engine->key_map[XK_KP_8] = SLK_KEY_NP8;
engine->key_map[XK_KP_9] = SLK_KEY_NP9;
engine->key_map[XK_KP_Multiply] = SLK_KEY_NP_MUL;
engine->key_map[XK_KP_Add] = SLK_KEY_NP_ADD;
engine->key_map[XK_KP_Divide] = SLK_KEY_NP_DIV;
engine->key_map[XK_KP_Subtract] = SLK_KEY_NP_SUB;
engine->key_map[XK_KP_Decimal] = SLK_KEY_NP_DECIMAL;*/
engine->mouse_map[SDL_BUTTON_LEFT] = SLK_BUTTON_LEFT;
engine->mouse_map[SDL_BUTTON_RIGHT] = SLK_BUTTON_RIGHT;
engine->mouse_map[SDL_BUTTON_MIDDLE] = SLK_BUTTON_MIDDLE;
engine->mouse_map[SDL_BUTTON_X1] = SLK_BUTTON_X1;
engine->mouse_map[SDL_BUTTON_X2] = SLK_BUTTON_X2;
glEnable(GL_TEXTURE_2D);
glGenTextures(1,&engine->gl_buffer);
glBindTexture(GL_TEXTURE_2D,engine->gl_buffer);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,engine->screen_width,engine->screen_height,
0,GL_RGBA,GL_UNSIGNED_BYTE,engine->default_draw_target->data);
engine->running = 1;
memset(engine->new_key_state,0,sizeof(engine->new_key_state));
memset(engine->new_mouse_state,0,sizeof(engine->new_mouse_state));
}
void SLK_end()
{
free(engine);
}
/*
(C) 2020 Lukas Holzbeierlein (Captain4LK)
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.
*/
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
void SLK_set_FPS(int FPS)
{
FPS = FPS;
frame_delay = 1000/FPS;
}
void SLK_quit()
{
running = 0;
}
int SLK_running()
{
return running;
}
void SLK_set_clear_color(int index)
{
clear_color = index;
}
void SLK_show_cursor(int shown)
{
SDL_ShowCursor(shown?SDL_ENABLE:SDL_DISABLE);
}
SLK_Color SLK_create_color(uint8 r, uint8 g, uint8 b, uint8 a)
{
SLK_Color c;
c.r = r;
c.g = g;
c.b = b;
c.a = 0;
return c;
}
SLK_Paxel SLK_create_paxel(uint8_t index, uint8_t mask)
{
SLK_Paxel p;
p.index = index;
p.mask = mask;
return p;
}
void SLK_update_screen()
{
for(int i = 0;i<target->width*target->height;i++)
target->data[i] = palette.colors[default_draw_target->data[i].index];
glClear(GL_COLOR_BUFFER_BIT);
glViewport(view_x,view_y,view_width,view_height);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,screen_width,screen_height,GL_RGBA,GL_UNSIGNED_BYTE,target->data);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);
glVertex3f(-1.0f,-1.0f,0.0f);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.0f,1.0f,0.0f);
glTexCoord2f(1.0, 0.0);
glVertex3f( 1.0f,1.0f,0.0f);
glTexCoord2f(1.0,1.0);
glVertex3f(1.0f,-1.0f,0.0f);
glEnd();
//glFinish();
SDL_GL_SwapWindow(sdl_window);
}
void SLK_update()
{
frametime = SDL_GetTicks()-framestart;
if(frame_delay>frametime)
SDL_Delay(frame_delay-frametime);
gone_fps++;
framestart = SDL_GetTicks();
//Event managing, done
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
running = 0;
break;
case SDL_MOUSEMOTION:
SLK_update_mouse(event.motion.x,event.motion.y);
break;
case SDL_KEYDOWN:
if(text_input_active&&event.key.keysym.sym==SDLK_BACKSPACE&&text_input[0]!='\0')
text_input[strlen(text_input)-1] = '\0';
if(event.key.state==SDL_PRESSED)
new_key_state[key_map[event.key.keysym.scancode]] = 1;
break;
case SDL_KEYUP:
if(event.key.state==SDL_RELEASED)
new_key_state[key_map[event.key.keysym.scancode]] = 0;
break;
case SDL_MOUSEBUTTONDOWN:
if(event.button.state==SDL_PRESSED)
new_mouse_state[mouse_map[event.button.button]] = 1;
break;
case SDL_MOUSEBUTTONUP:
if(event.button.state==SDL_RELEASED)
new_mouse_state[mouse_map[event.button.button]] = 0;
break;
case SDL_TEXTINPUT:
if(text_input_active)
strcat(text_input,event.text.text);
break;
}
}
//-------------------------------------------
for(int i = 0; i<256; i++)
{
keyboard_state[i].released = 0;
keyboard_state[i].pressed = 0;
if(new_key_state[i]!=old_key_state[i])
{
if(new_key_state[i])
{
keyboard_state[i].pressed = !keyboard_state[i].held;
keyboard_state[i].held = 1;
}
else
{
keyboard_state[i].released = 1;
keyboard_state[i].held = 0;
}
}
old_key_state[i] = new_key_state[i];
}
for(int i = 0;i<6;i++)
{
mouse_state[i].pressed = 0;
mouse_state[i].released = 0;
if(new_mouse_state[i]!=old_mouse_state[i])
{
if(new_mouse_state[i])
{
mouse_state[i].pressed = !mouse_state[i].held;
mouse_state[i].held =1;
}
else
{
mouse_state[i].released = 1;
mouse_state[i].held = 0;
}
}
old_mouse_state[i] = new_mouse_state[i];
}
}
void SLK_update_viewport()
{
if (view_height<window_height)
{
int pixel_scale = window_height/screen_height;
view_width = screen_width*pixel_scale;
view_height = screen_height*pixel_scale;
}
else
{
int pixel_scale = window_width/screen_width;
view_width = screen_width*pixel_scale;
view_height = screen_height*pixel_scale;
}
view_x = (window_width-view_width)/2;
view_y = (window_height-view_height)/2;
}
void SLK_update_mouse(int x, int y)
{
x-=view_x;
y-=view_y;
mouse_x_cache = (int)(((float)x/(float)(window_width-(view_x*2))*(float)screen_width));
mouse_y_cache = (int)(((float)y/(float)(window_height-(view_y*2))*(float)screen_height));
if(mouse_x_cache>=screen_width)
mouse_x_cache = screen_width-1;
if(mouse_y_cache>=screen_height)
mouse_y_cache = screen_height-1;
if(mouse_x_cache<0)
mouse_x_cache = 0;
if(mouse_y_cache<1)
mouse_y_cache = 1;
}
void SLK_set_draw_target(SLK_Sprite *new_target)
{
if(new_target)
draw_target = new_target;
else
draw_target = default_draw_target;
}
void SLK_setup(int width, int height, const char *title, int fullscreen, int pixel_scale)
{
screen_width = width;
screen_height = height;
font_sprite = SLK_load_sprite("data/font8x8.slk");
SLK_load_palette("data/palette.pal");
default_draw_target = SLK_create_sprite(screen_width,screen_height);
target = SLK_create_sprite_rgb(screen_width,screen_height);
SLK_set_draw_target(NULL);
if(SDL_Init(SDL_INIT_EVERYTHING)<0)
{
printf("FATAL ERROR: failed to init sdl\n");
exit(-1);
}
SDL_GL_LoadLibrary(NULL);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,1);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
if(fullscreen)
sdl_window = SDL_CreateWindow(title,SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,0,0,SDL_WINDOW_FULLSCREEN_DESKTOP|SDL_WINDOW_OPENGL);
else
sdl_window = SDL_CreateWindow(title,SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,width*pixel_scale,height*pixel_scale,SDL_WINDOW_OPENGL);
if(!sdl_window)
{
printf("FATAL ERROR: failed to create window\n");
exit(-1);
}
sdl_gl_context = SDL_GL_CreateContext(sdl_window);
if(!sdl_gl_context)
{
printf("FATAL ERROR: failed to create opengl context\n");
exit(-1);
}
SDL_GL_SetSwapInterval(0);
printf("OpenGL loaded\n");
printf("Vendor: %s\n",glGetString(GL_VENDOR));
printf("Renderer: %s\n",glGetString(GL_RENDERER));
printf("Version: %s\n",glGetString(GL_VERSION));
printf("SDL_GL_GetSwapInterval: %d\nErrors: %s\n",SDL_GL_GetSwapInterval(),SDL_GetError());
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
SDL_GetWindowSize(sdl_window,&window_width,&window_height);
glViewport(0,0,width,height);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClear(GL_COLOR_BUFFER_BIT);
SLK_update_viewport();
key_map[0x00] = SLK_KEY_NONE;
key_map[SDL_SCANCODE_A] = SLK_KEY_A;
key_map[SDL_SCANCODE_B] = SLK_KEY_B;
key_map[SDL_SCANCODE_C] = SLK_KEY_C;
key_map[SDL_SCANCODE_D] = SLK_KEY_D;
key_map[SDL_SCANCODE_E] = SLK_KEY_E;
key_map[SDL_SCANCODE_F] = SLK_KEY_F;
key_map[SDL_SCANCODE_G] = SLK_KEY_G;
key_map[SDL_SCANCODE_H] = SLK_KEY_H;
key_map[SDL_SCANCODE_I] = SLK_KEY_I;
key_map[SDL_SCANCODE_J] = SLK_KEY_J;
key_map[SDL_SCANCODE_K] = SLK_KEY_K;
key_map[SDL_SCANCODE_L] = SLK_KEY_L;
key_map[SDL_SCANCODE_M] = SLK_KEY_M;
key_map[SDL_SCANCODE_N] = SLK_KEY_N;
key_map[SDL_SCANCODE_O] = SLK_KEY_O;
key_map[SDL_SCANCODE_P] = SLK_KEY_P;
key_map[SDL_SCANCODE_Q] = SLK_KEY_Q;
key_map[SDL_SCANCODE_R] = SLK_KEY_R;
key_map[SDL_SCANCODE_S] = SLK_KEY_S;
key_map[SDL_SCANCODE_T] = SLK_KEY_T;
key_map[SDL_SCANCODE_U] = SLK_KEY_U;
key_map[SDL_SCANCODE_V] = SLK_KEY_V;
key_map[SDL_SCANCODE_W] = SLK_KEY_W;
key_map[SDL_SCANCODE_X] = SLK_KEY_X;
key_map[SDL_SCANCODE_Y] = SLK_KEY_Y;
key_map[SDL_SCANCODE_Z] = SLK_KEY_Z;
key_map[SDL_SCANCODE_F1] = SLK_KEY_F1;
key_map[SDL_SCANCODE_F2] = SLK_KEY_F2;
key_map[SDL_SCANCODE_F3] = SLK_KEY_F3;
key_map[SDL_SCANCODE_F4] = SLK_KEY_F4;
key_map[SDL_SCANCODE_F5] = SLK_KEY_F5;
key_map[SDL_SCANCODE_F6] = SLK_KEY_F6;
key_map[SDL_SCANCODE_F7] = SLK_KEY_F7;
key_map[SDL_SCANCODE_F8] = SLK_KEY_F8;
key_map[SDL_SCANCODE_F9] = SLK_KEY_F9;
key_map[SDL_SCANCODE_F10] = SLK_KEY_F10;
key_map[SDL_SCANCODE_F11] = SLK_KEY_F11;
key_map[SDL_SCANCODE_F12] = SLK_KEY_F12;
key_map[SDL_SCANCODE_DOWN] = SLK_KEY_DOWN;
key_map[SDL_SCANCODE_LEFT] = SLK_KEY_LEFT;
key_map[SDL_SCANCODE_RIGHT] = SLK_KEY_RIGHT;
key_map[SDL_SCANCODE_UP] = SLK_KEY_UP;
key_map[SDL_SCANCODE_RETURN] = SLK_KEY_ENTER;
key_map[SDL_SCANCODE_BACKSPACE] = SLK_KEY_BACK;
key_map[SDL_SCANCODE_ESCAPE] = SLK_KEY_ESCAPE;
key_map[SDL_SCANCODE_TAB] = SLK_KEY_TAB;
key_map[SDL_SCANCODE_LGUI] = SLK_KEY_HOME;
/*key_map[XK_End] = SLK_KEY_END;
key_map[XK_Page_Up] = SLK_KEY_PGUP;
key_map[XK_Page_Down] = SLK_KEY_PGDN;
key_map[XK_Insert] = SLK_KEY_INS;
key_map[XK_Shift_L] = SLK_KEY_SHIFT;
key_map[XK_Shift_R] = SLK_KEY_SHIFT;
key_map[XK_Control_L] = SLK_KEY_CTRL;
key_map[XK_Control_R] = SLK_KEY_CTRL;*/
key_map[SDL_SCANCODE_SPACE] = SLK_KEY_SPACE;
/*key_map[XK_0] = SLK_KEY_K0;
key_map[XK_1] = SLK_KEY_K1;
key_map[XK_2] = SLK_KEY_K2;
key_map[XK_3] = SLK_KEY_K3;
key_map[XK_4] = SLK_KEY_K4;
key_map[XK_5] = SLK_KEY_K5;
key_map[XK_6] = SLK_KEY_K6;
key_map[XK_7] = SLK_KEY_K7;
key_map[XK_8] = SLK_KEY_K8;
key_map[XK_9] = SLK_KEY_K9;
key_map[XK_KP_0] = SLK_KEY_NP0;
key_map[XK_KP_1] = SLK_KEY_NP1;
key_map[XK_KP_2] = SLK_KEY_NP2;
key_map[XK_KP_3] = SLK_KEY_NP3;
key_map[XK_KP_4] = SLK_KEY_NP4;
key_map[XK_KP_5] = SLK_KEY_NP5;
key_map[XK_KP_6] = SLK_KEY_NP6;
key_map[XK_KP_7] = SLK_KEY_NP7;
key_map[XK_KP_8] = SLK_KEY_NP8;
key_map[XK_KP_9] = SLK_KEY_NP9;
key_map[XK_KP_Multiply] = SLK_KEY_NP_MUL;
key_map[XK_KP_Add] = SLK_KEY_NP_ADD;
key_map[XK_KP_Divide] = SLK_KEY_NP_DIV;
key_map[XK_KP_Subtract] = SLK_KEY_NP_SUB;
key_map[XK_KP_Decimal] = SLK_KEY_NP_DECIMAL;*/
mouse_map[SDL_BUTTON_LEFT] = SLK_BUTTON_LEFT;
mouse_map[SDL_BUTTON_RIGHT] = SLK_BUTTON_RIGHT;
mouse_map[SDL_BUTTON_MIDDLE] = SLK_BUTTON_MIDDLE;
mouse_map[SDL_BUTTON_X1] = SLK_BUTTON_X1;
mouse_map[SDL_BUTTON_X2] = SLK_BUTTON_X2;
glEnable(GL_TEXTURE_2D);
glGenTextures(1,&gl_buffer);
glBindTexture(GL_TEXTURE_2D,gl_buffer);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,screen_width,screen_height,
0,GL_RGB,GL_UNSIGNED_BYTE,target->data);
running = 1;
memset(new_key_state,0,sizeof(new_key_state));
memset(new_mouse_state,0,sizeof(new_mouse_state));
}
void SLK_end()
{
}
void SLK_start_timer()
{
timer = clock();
}
void SLK_end_timer()
{
printf("Time: %lf\n",((double)(clock()-timer)/CLOCKS_PER_SEC));
}

View file

@ -1,5 +1,5 @@
/*
(C) 2019 Lukas Holzbeierlein (Captain4LK)
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -23,45 +23,48 @@
void SLK_clear_screen()
{
for(int b = 0;b<engine->draw_target->width*engine->draw_target->height;b++)
engine->draw_target->data[b] = engine->clear_color;
for(int b = 0;b<draw_target->width*draw_target->height;b++)
{
draw_target->data[b].index = clear_color;
draw_target->data[b].mask = SLK_OPAQUE;
}
}
void SLK_draw_rectangle(int x, int y, int width, int height, SLK_Color c)
void SLK_draw_rectangle(int x, int y, int width, int height, SLK_Paxel p)
{
width--;
height--;
for(int dx = 0;dx<width+1;dx++)
{
SLK_draw(dx+x,y,c);
SLK_draw(dx+x,y+width,c);
SLK_draw(dx+x,y,p);
SLK_draw(dx+x,y+height,p);
}
for(int dy = 0;dy<height+1;dy++)
{
SLK_draw(x,y+dy,c);
SLK_draw(x+width,y+dy,c);
SLK_draw(x,y+dy,p);
SLK_draw(x+width,y+dy,p);
}
}
void SLK_fill_rectangle(int x, int y, int width, int height, SLK_Color c)
void SLK_fill_rectangle(int x, int y, int width, int height, SLK_Paxel p)
{
for(int x_ = x;x_<x+width;x_++)
for(int y_ = y;y_<y+height;y_++)
SLK_draw(x_,y_,c);
SLK_draw(x_,y_,p);
}
void SLK_draw(int x, int y, SLK_Color c)
void SLK_draw(int x, int y, SLK_Paxel p)
{
if(INBOUNDS(0,engine->draw_target->width,x)&&INBOUNDS(0,engine->draw_target->height,y))
engine->draw_target->data[y*engine->draw_target->width+x] = c;
if(INBOUNDS(0,draw_target->width,x)&&INBOUNDS(0,draw_target->height,y))
draw_target->data[y*draw_target->width+x].index = (draw_target->data[y*draw_target->width+x].index&p.mask)|p.index;
}
void SLK_draw_nc(int x, int y, SLK_Color c)
void SLK_draw_nc(int x, int y, SLK_Paxel p)
{
engine->draw_target->data[y*engine->draw_target->width+x] = c;
draw_target->data[y*draw_target->width+x].index = (draw_target->data[y*draw_target->width+x].index&p.mask)|p.index;
}
void SLK_draw_string(int x, int y, int scale, const char *text, SLK_Color c)
void SLK_draw_string(int x, int y, int scale, const char *text, SLK_Paxel p)
{
int32 sx = 0;
int32 sy = 0;
@ -82,104 +85,77 @@ void SLK_draw_string(int x, int y, int scale, const char *text, SLK_Color c)
{
for(uint32 x_ = 0;x_<8;x_++)
for(uint32 y_ = 0;y_<8;y_++)
if(font_sprite->data[(y_+oy*8)*128+x_+ox*8].a)
if(!font_sprite->data[(y_+oy*8)*128+x_+ox*8].mask)
for(uint32 is = 0;is<scale;is++)
for(uint32 js = 0;js<scale;js++)
SLK_draw(x+sx+(x_*scale)+is,y+sy+(y_*scale)+js,c);
SLK_draw(x+sx+(x_*scale)+is,y+sy+(y_*scale)+js,p);
}
else
{
for(uint32 x_ = 0; x_ < 8; x_++)
for(uint32 y_ = 0; y_ < 8; y_++)
if(font_sprite->data[(y_+oy*8)*128+x_+ox*8].a)
SLK_draw(x+sx+x_,y+sy+y_,c);
if(!font_sprite->data[(y_+oy*8)*128+x_+ox*8].mask)
SLK_draw(x+sx+x_,y+sy+y_,p);
}
sx += 8*scale;
}
}
}
void SLK_draw_partial_sprite_rgb(SLK_Sprite_rgb *s, int x, int y, int ox, int oy, int width, int height)
void SLK_draw_sprite_partial(SLK_Sprite *s, int x, int y, int ox, int oy, int width, int height)
{
for(int tx = 0; tx < width; tx++)
{
for(int ty = 0; ty < height; ty++)
{
SLK_Color c = SLK_get_pixel_rgb(s, tx + ox, ty + oy);
SLK_draw(x + tx, y +ty, c);
SLK_Paxel p = SLK_get_paxel(s, tx + ox, ty + oy);
SLK_draw(x+ tx,y+ty,p);
}
}
}
void SLK_draw_sprite_pal(SLK_Sprite_pal *s, int x, int y)
void SLK_draw_sprite(const SLK_Sprite *s, const int x, const int y)
{
SLK_Color c;
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = s->width;
int draw_end_y = s->height;
if(x<0)
draw_start_x = abs(x);
if(y<0)
draw_start_y = abs(y);
if(x+draw_end_x>engine->draw_target->width)
draw_end_x = s->width+(engine->draw_target->width-x-draw_end_x);
if(y+draw_end_y>engine->draw_target->height)
draw_end_y = s->height+(engine->draw_target->height-y-draw_end_y);
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
c = s->palette->colors[s->data[y1*s->width+x1]];
if(c.a)
engine->draw_target->data[(y1+y)*engine->draw_target->width+x1+x] = c;
}
}
void SLK_draw_sprite_rgb(SLK_Sprite_rgb *s, int x, int y)
{
SLK_Color c;
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = s->width;
int draw_end_y = s->height;
if(x<0)
draw_start_x = abs(x);
if(y<0)
draw_start_y = abs(y);
if(x+draw_end_x>engine->draw_target->width)
draw_end_x = s->width+(engine->draw_target->width-x-draw_end_x);
if(y+draw_end_y>engine->draw_target->height)
draw_end_y = s->height+(engine->draw_target->height-y-draw_end_y);
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
c = s->data[y1*s->width+x1];
if(c.a)
engine->draw_target->data[(y1+y)*engine->draw_target->width+x1+x] = c;
}
}
}
void SLK_draw_sprite_flip_rgb(SLK_Sprite_rgb *s, int x, int y, int flip)
{
SLK_Color c;
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = s->width;
int draw_end_y = s->height;
if(x<0)
draw_start_x = abs(x);
draw_start_x = -x;
if(y<0)
draw_start_y = abs(y);
if(x+draw_end_x>engine->draw_target->width)
draw_end_x = s->width+(engine->draw_target->width-x-draw_end_x);
if(y+draw_end_y>engine->draw_target->height)
draw_end_y = s->height+(engine->draw_target->height-y-draw_end_y);
draw_start_y = -y;
if(x+draw_end_x>draw_target->width)
draw_end_x = s->width+(draw_target->width-x-draw_end_x);
if(y+draw_end_y>draw_target->height)
draw_end_y = s->height+(draw_target->height-y-draw_end_y);
for(int x1 = draw_start_x;x1<draw_end_x;x1++)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
SLK_Paxel p = s->data[y1*s->width+x1];
draw_target->data[(y1+y)*draw_target->width+x1+x].index = (draw_target->data[(y1+y)*draw_target->width+x1+x].index&p.mask)|p.index;
}
}
}
void SLK_draw_sprite_flip(const SLK_Sprite *s, const int x, const int y, const int flip)
{
SLK_Paxel p;
int draw_start_y = 0;
int draw_start_x = 0;
int draw_end_x = s->width;
int draw_end_y = s->height;
if(x<0)
draw_start_x = -x;
if(y<0)
draw_start_y = -y;
if(x+draw_end_x>draw_target->width)
draw_end_x = s->width+(draw_target->width-x-draw_end_x);
if(y+draw_end_y>draw_target->height)
draw_end_y = s->height+(draw_target->height-y-draw_end_y);
if(flip)
{
@ -187,9 +163,8 @@ void SLK_draw_sprite_flip_rgb(SLK_Sprite_rgb *s, int x, int y, int flip)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
c = s->data[y1*s->width+(s->width-x1-1)];
if(c.a)
engine->draw_target->data[(y1+y)*engine->draw_target->width+x1+x] = c;
p = s->data[y1*s->width+(s->width-x1-1)];
draw_target->data[(y1+y)*draw_target->width+x1+x].index = (draw_target->data[(y1+y)*draw_target->width+x1+x].index&p.mask)|p.index;
}
}
}
@ -199,16 +174,15 @@ void SLK_draw_sprite_flip_rgb(SLK_Sprite_rgb *s, int x, int y, int flip)
{
for(int y1 = draw_start_y;y1<draw_end_y;y1++)
{
c = s->data[y1*s->width+x1];
if(c.a)
engine->draw_target->data[(y1+y)*engine->draw_target->width+x1+x] = c;
p = s->data[y1*s->width+x1];
draw_target->data[(y1+y)*draw_target->width+x1+x].index = (draw_target->data[(y1+y)*draw_target->width+x1+x].index&p.mask)|p.index;
}
}
}
}
void SLK_draw_line(int x1, int y1, int x2, int y2, SLK_Color c)
void SLK_draw_line(int x1, int y1, int x2, int y2, SLK_Paxel p)
{
int changed = 0;
int x = x1;
@ -231,7 +205,7 @@ void SLK_draw_line(int x1, int y1, int x2, int y2, SLK_Color c)
for(int i = 1;i<=dx;i++)
{
SLK_draw(x,y,c);
SLK_draw(x,y,p);
while(error>=0)
{
@ -250,4 +224,10 @@ void SLK_draw_line(int x1, int y1, int x2, int y2, SLK_Color c)
}
}
void SLK_draw_vertical_line(int x, int y1, int y2, SLK_Paxel p)
{
for(int y = y1;y<y1+1;y++)
{
draw_target->data[(y)*draw_target->width+x].index = (draw_target->data[(y)*draw_target->width+x].index&p.mask)|p.index;
}
}

View file

@ -23,36 +23,51 @@
int SLK_key_down(int key)
{
return engine->keyboard_state[key].held;
return keyboard_state[key].held;
}
int SLK_key_pressed(int key)
{
return engine->keyboard_state[key].pressed;
return keyboard_state[key].pressed;
}
int SLK_key_released(int key)
{
return engine->keyboard_state[key].released;
return keyboard_state[key].released;
}
int SLK_mouse_down(int key)
{
return engine->mouse_state[key].held;
return mouse_state[key].held;
}
int SLK_mouse_pressed(int key)
{
return engine->mouse_state[key].pressed;
return mouse_state[key].pressed;
}
int SLK_mouse_released(int key)
{
return engine->mouse_state[key].released;
return mouse_state[key].released;
}
void SLK_get_mouse_pos(int *x, int *y)
{
*x = engine->mouse_x_cache;
*y = engine->mouse_y_cache;
*x = mouse_x_cache;
*y = mouse_y_cache;
}
void SLK_start_text_input(char *text)
{
text_input = text;
text_input_active = 1;
SDL_StartTextInput();
}
void SLK_stop_text_input()
{
text_input_active = 0;
SDL_StopTextInput();
}

View file

@ -1,5 +1,5 @@
/*
(C) 2019 Lukas Holzbeierlein (Captain4LK)
(C) 2020 Lukas Holzbeierlein (Captain4LK)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
@ -21,7 +21,7 @@
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
SLK_Sprite_rgb *SLK_load_sprite_rgb(const char *path)
/*SLK_Sprite_rgb *SLK_load_sprite_rgb(const char *path)
{
SLK_Sprite_rgb *s = NULL;
int width,height;
@ -73,7 +73,7 @@ SLK_Sprite_rgb *SLK_load_sprite_rgb(const char *path)
for (int x = 0; x<width; x++)
{
png_bytep px = &(row[x * 4]);
s->data[y*s->width+x] = SLK_create_color(px[0],px[1],px[2],px[3]);
s->data[y*s->width+x] = SLK_create_color(px[0],px[1],px[2],px[3]);
}
}
@ -135,4 +135,66 @@ void SLK_save_sprite_rgb(const char *path, SLK_Sprite_rgb *s)
fclose(f);
}*/
SLK_Sprite *SLK_load_sprite(const char *path)
{
FILE *f = fopen(path,"rb");
if(!f)
return SLK_create_sprite(1,1);
int width, height;
fread(&width,sizeof(int),1,f);
fread(&height,sizeof(int),1,f);
SLK_Sprite *s = SLK_create_sprite(width,height);
fread(s->data,sizeof(SLK_Paxel),width*height,f);
fclose(f);
return s;
}
void SLK_save_sprite(const char *path, SLK_Sprite *s)
{
FILE *f = fopen(path,"wb");
if(!f)
return;
fwrite(&s->width,sizeof(int),1,f);
fwrite(&s->height,sizeof(int),1,f);
fwrite(s->data,sizeof(SLK_Paxel),s->width*s->height,f);
fclose(f);
}
void SLK_load_palette(const char *path)
{
FILE *f = fopen(path,"r");
if(!f)
{
printf("Unable to load palette\n");
return;
}
char buffer[512];
int colors = 0;
for(int i = 0;i<259&&fgets(buffer,512,f);i++)
{
if(i==2)
{
int found;
sscanf(buffer,"%d",&found);
printf("Found %d colors\n",found);
}
else if(i>2)
{
int r,g,b;
sscanf(buffer,"%d %d %d",&r,&g,&b);
palette.colors[colors].r = r;
palette.colors[colors].g = g;
palette.colors[colors].b = b;
palette.colors[colors].a = 255;
colors++;
}
}
}

52
src/SLK_sprite.c Normal file
View file

@ -0,0 +1,52 @@
/*
(C) 2019 Lukas Holzbeierlein (Captain4LK)
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.
*/
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
SLK_Sprite *SLK_create_sprite(int width, int height)
{
SLK_Sprite *s = malloc(sizeof(SLK_Sprite));
s->width = width;
s->height = height;
s->data = malloc(width*height*sizeof(SLK_Paxel));
return s;
}
void SLK_destroy_sprite(SLK_Sprite *s)
{
free(s->data);
free(s);
}
SLK_Paxel SLK_get_paxel(SLK_Sprite *s, int x, int y)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
return s->data[y*s->width+x];
else
return (SLK_Paxel){0,0};
}
void SLK_set_paxel(SLK_Sprite *s, int x, int y, SLK_Paxel c)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
s->data[y*s->width+x] = c;
}

View file

@ -1,119 +0,0 @@
/*
(C) 2019 Lukas Holzbeierlein (Captain4LK)
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.
*/
#include "../include/SLK/SLK.h"
#include "SLK_variables.h"
SLK_Sprite_pal *SLK_create_sprite_pal(int width, int height)
{
SLK_Sprite_pal *s = malloc(sizeof(SLK_Sprite_pal));
s->width = width;
s->height = height;
s->data = malloc(width*height);
s->palette = &default_palette;
return s;
}
void SLK_destroy_sprite_pal(SLK_Sprite_pal *s)
{
if(s->palette!=&default_palette)
SLK_destroy_palette(s->palette);
free(s->data);
free(s);
}
uint8 SLK_get_pixel_pal(SLK_Sprite_pal *s, int x, int y)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
return s->data[y*s->width+x];
else
return 0;
}
void SLK_set_pixel_pal(SLK_Sprite_pal *s, int x, int y, uint8 c)
{
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
s->data[y*s->width+x] = c;
}
void SLK_set_palette(SLK_Sprite_pal *s, SLK_Palette *p)
{
s->palette = p;
}
SLK_Palette *SLK_get_palette(SLK_Sprite_pal *s)
{
return s->palette;
}
SLK_Sprite_pal *SLK_sprite_rgb_to_pal(SLK_Sprite_rgb *s)
{
SLK_Sprite_pal *sp = SLK_create_sprite_pal(s->width,s->height);
for(int x = 0;x<s->width;x++)
{
for(int y = 0;y<s->height;y++)
{
int need_new_color = 1;
for(int c = 0;c<sp->palette->used;c++)
{
if(SLK_get_pixel_rgb(s,x,y).n==SLK_get_palette_color(sp->palette,c).n)
{
SLK_set_pixel_pal(sp,x,y,c);
need_new_color = 0;
break;
}
}
if(need_new_color)
{
SLK_set_palette_color(sp->palette,sp->palette->used,SLK_get_pixel_rgb(s,x,y));
SLK_set_pixel_pal(sp,x,y,sp->palette->used);
sp->palette->used++;
}
}
}
return sp;
}
SLK_Palette *SLK_create_palette()
{
SLK_Palette *p = malloc(sizeof(SLK_Palette));
memset(p,0,sizeof(SLK_Palette));
return p;
}
void SLK_destroy_palette(SLK_Palette *p)
{
free(p);
}
void SLK_set_palette_color(SLK_Palette *p, uint8 index, SLK_Color c)
{
p->colors[index] = c;
}
SLK_Color SLK_get_palette_color(SLK_Palette *p, uint8 index)
{
return p->colors[index];
}

View file

@ -22,9 +22,9 @@
#include "SLK_variables.h"
SLK_Sprite_rgb *SLK_create_sprite_rgb(int width, int height)
{
{
SLK_Sprite_rgb *s = malloc(sizeof(SLK_Sprite_rgb));
if(s==NULL
if(s==NULL)
{
printf("Failed to allocate memory for Sprite\n");
exit(-1);
@ -32,7 +32,9 @@ SLK_Sprite_rgb *SLK_create_sprite_rgb(int width, int height)
s->width = width;
s->height = height;
s->data = malloc(width*height*sizeof(SLK_Color));
memset(s->data,0,width*height*sizeof(SLK_Color));
return s;
}
@ -56,19 +58,3 @@ void SLK_set_pixel_rgb(SLK_Sprite_rgb *s, int x, int y, SLK_Color c)
if(INBOUNDS(0,s->width,x)&&INBOUNDS(0,s->height,y))
s->data[y*s->width+x] = c;
}
SLK_Sprite_rgb *SLK_sprite_pal_to_rgb(SLK_Sprite_pal *s)
{
SLK_Sprite_rgb *sr = SLK_create_sprite_rgb(s->width,s->height);
for(int x = 0;x<s->width;x++)
{
for(int y = 0;y<s->height;y++)
{
SLK_set_pixel_rgb(sr,x,y,s->palette->colors[SLK_get_pixel_pal(s,x,y)]);
}
}
return sr;
}

View file

@ -22,50 +22,57 @@
#define _SLK_VARIABLES_H_
typedef struct
{
SLK_Sprite_rgb *draw_target;
SLK_Sprite_rgb *default_draw_target;
SLK_Color clear_color;
SLK_Sprite_rgb *SLK_create_sprite_rgb(int width, int height);
void SLK_destroy_sprite_rgb(SLK_Sprite_rgb *s);
SLK_Color SLK_get_pixel_rgb(SLK_Sprite_rgb *s, int x, int y);
void SLK_set_pixel_rgb(SLK_Sprite_rgb *s, int x, int y, SLK_Color c);
SLK_Sprite *draw_target;
SLK_Sprite *default_draw_target;
SLK_Sprite_rgb *target;
int clear_color;
int screen_width;
int screen_height;
int window_width;
int window_height;
int view_x;
int view_y;
int view_width;
int view_height;
int running;
int mouse_x_cache;
int mouse_y_cache;
uint8 new_key_state[256];
uint8 old_key_state[256];
SLK_Button keyboard_state[256];
uint8 new_mouse_state[6];
uint8 old_mouse_state[6];
SLK_Button mouse_state[6];
uint8 key_map[SDL_NUM_SCANCODES];
uint8 mouse_map[6];
int screen_width;
int screen_height;
int window_width;
int window_height;
int view_x;
int view_y;
int view_width;
int view_height;
int running;
SDL_Window *sdl_window;
SDL_GLContext sdl_gl_context;
int mouse_x_cache;
int mouse_y_cache;
GLuint gl_buffer;
uint8 new_key_state[256];
uint8 old_key_state[256];
SLK_Button keyboard_state[256];
uint8 new_mouse_state[6];
uint8 old_mouse_state[6];
SLK_Button mouse_state[6];
uint8 key_map[SDL_NUM_SCANCODES];
uint8 mouse_map[6];
SDL_Window *sdl_window;
SDL_GLContext sdl_gl_context;
GLuint gl_buffer;
int frametime;
Uint32 framestart;
int FPS;
int frame_delay;
uint8 gone_fps;
}SLK_engine;
int frametime;
Uint32 framestart;
int FPS;
int frame_delay;
uint8 gone_fps;
char *text_input;
int text_input_active;
void load_font_sprite();
SLK_Sprite_rgb *font_sprite;
SLK_engine *engine;
SLK_Palette default_palette;
SLK_Sprite *font_sprite;
SLK_Palette palette;
clock_t timer;
#endif