me.fier.engine/test.c

145 lines
3.0 KiB
C
Raw Normal View History

2023-05-14 10:21:03 +00:00
#include <stdio.h>
#include <stdlib.h>
#include "modules/engine/main.c"
#include "modules/engine/frontend/sdl/main.c"
#include "modules/engine/frontend/generic/textures.c"
//#include "modules/engine/frontend/sdl/textures.c" // TODO
void handleEvent(struct ENGINE_EVENT event) {
if (event.type == ENGINE_EVENT_TYPE_EXIT) {
exit(0);
}
}
int frame = 0;
int frameSec = 0;
Uint32 lastSec = 0;
char tr, tg, tb;
struct ENGINE_TEXTURE * texture;
void tick() {
int y = 0;
while (y < engine_height) {
int x = 0;
while (x < engine_width) {
/*tr = (char)(x + y) + ((char)frame * 1);
tg = (char)(x + y) + ((char)frame * 3);
tb = (char)(x + y) + ((char)frame * 5);*/
/*tr = (char)(x + y) * (char)frame * 1;
tg = (char)(x + y) * (char)frame * 3;
tb = (char)(x + y) * (char)frame * 5;*/
tr = (char)((x * y) + 64) + frame;
tg = (char)((x * y) + 128) + frame;
tb = (char)((x * y) + 192) + frame;
/*int part = engine_width / 3;
if (x < part * 1) {
tr = 255;
tg = 0;
tb = 0;
} else if (x < part * 2) {
tr = 0;
tg = 255;
tb = 0;
} else {
tr = 0;
tg = 0;
tb = 255;
}*/
/*tr = 0;
tg = 255 - ((char)((x * y) + 128) + frame);
tb = 0;*/
/*tr = (char)(((float)x / (float)engine_width) * 255);
tg = 255 - tr;
tb = (char)(((float)y / (float)engine_height) * 255);*/
engine_setColor(tr,tg,tb,255);
engine_drawPixel(x,y);
++x;
}
++y;
}
//y = 0;
//while (y < engine_height) {
// int x = 0;
// while (x < engine_width) {
// tr = (char)(x + y) + ((char)frame * 1);
// tg = (char)(x + y) + ((char)frame * 3);
// tb = (char)(x + y) + ((char)frame * 5);
/*tr = (char)(x + y) * (char)frame * 1;
tg = (char)(x + y) * (char)frame * 3;
tb = (char)(x + y) * (char)frame * 5;*/
/*tr = (char)((x * y) + 64) + frame;
tg = (char)((x * y) + 128) + frame;
tb = (char)((x * y) + 192) + frame;*/
/*int part = engine_width / 3;
if (x < part * 1) {
tr = 255;
tg = 0;
tb = 0;
} else if (x < part * 2) {
tr = 0;
tg = 255;
tb = 0;
} else {
tr = 0;
tg = 0;
tb = 255;
}*/
/*tr = 0;
tg = 255 - ((char)((x * y) + 128) + frame);
tb = 0;*/
/*tr = (char)(((float)x / (float)engine_width) * 255);
tg = 255 - tr;
tb = (char)(((float)y / (float)engine_height) * 255);*/
// engine_setColor(tr,tg,tb,128);
// engine_drawPixel(x,y);
// ++x;
// }
// ++y;
//}
engine_renderTexture2D(texture,5,5);
frame += 1;
frameSec += 1;
Uint32 tick = SDL_GetTicks();
if (tick - lastSec >= 1000) {
printf("FPS: %d\n",frameSec);
lastSec = tick;
frameSec = 0;
}
engine_render();
//engine_sleep(33);
}
int main(int argc, char **argv) {
texture = engine_createTexture(8,8);
engine_fileToTexture(texture,"assets/textures/fier.rgba");
for (int i = 0; i < argc; ++i) {
printf("argv[%d]: %s\n", i, argv[i]);
}
engine_init(256,256,"Game");
while (1) {
struct ENGINE_EVENT event = engine_getEvent();
if (event.type != ENGINE_EVENT_TYPE_NONE) {
handleEvent(event);
} else {
tick();
}
}
}