|
@@ -15,69 +15,7 @@
|
|
|
|
|
|
#include <log.h>
|
|
|
|
|
|
-SDL_Window *window = NULL;
|
|
|
-SDL_Renderer *renderer = NULL;
|
|
|
-bool isRunning = false;
|
|
|
-uint32_t *frameBuffer = NULL;
|
|
|
-SDL_Texture *frameBufferTexture = NULL;
|
|
|
-int windowWidth = 800;
|
|
|
-int windowHeight = 600;
|
|
|
-
|
|
|
-#define color_buffer frameBuffer;
|
|
|
-
|
|
|
-bool initialiseWindow(bool fullScreen)
|
|
|
-{
|
|
|
- bool ret = false;
|
|
|
- int windowFlags = 0;
|
|
|
-
|
|
|
- if (SDL_Init(SDL_INIT_EVERYTHING))
|
|
|
- {
|
|
|
- log(TLOG_PANIC, NULL, "SDL Initialisation error!! error: %s", SDL_GetError());
|
|
|
- goto exit;
|
|
|
- }
|
|
|
-
|
|
|
- log(TLOG_DEBUG, NULL, "SDL properly initialised!");
|
|
|
-
|
|
|
- if (fullScreen)
|
|
|
- {
|
|
|
- log(TLOG_DEBUG, NULL, "Will go fullscreen! Fasten your seatbelts!");
|
|
|
- SDL_DisplayMode displayMode;
|
|
|
- SDL_GetCurrentDisplayMode(0, &displayMode);
|
|
|
-
|
|
|
- windowWidth = displayMode.w;
|
|
|
- windowHeight = displayMode.h;
|
|
|
-
|
|
|
- windowFlags = SDL_WINDOW_BORDERLESS;
|
|
|
- }
|
|
|
-
|
|
|
- window = SDL_CreateWindow(NULL,
|
|
|
- SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
|
|
- windowWidth, windowHeight,
|
|
|
- windowFlags);
|
|
|
- if (window == NULL)
|
|
|
- {
|
|
|
- log(TLOG_PANIC, NULL, "SDL Window creation error: %s", SDL_GetError());
|
|
|
- goto exit;
|
|
|
- }
|
|
|
- log(TLOG_DEBUG, NULL, "SDL Window created!");
|
|
|
-
|
|
|
- renderer = SDL_CreateRenderer(window, -1, 0);
|
|
|
- if (renderer == NULL)
|
|
|
- {
|
|
|
- log(TLOG_PANIC, NULL, "SDL Renderer creation error: %s", SDL_GetError());
|
|
|
- goto exit;
|
|
|
- }
|
|
|
- log(TLOG_DEBUG, NULL, "SDL Renderer created!");
|
|
|
-
|
|
|
- if (fullScreen)
|
|
|
- {
|
|
|
- SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
|
|
- }
|
|
|
-
|
|
|
- ret = true;
|
|
|
-exit:
|
|
|
- return ret;
|
|
|
-}
|
|
|
+#include <display.h>
|
|
|
|
|
|
void setup()
|
|
|
{
|
|
@@ -88,10 +26,8 @@ void setup()
|
|
|
goto exit;
|
|
|
}
|
|
|
|
|
|
- frameBufferTexture = SDL_CreateTexture(renderer,
|
|
|
- SDL_PIXELFORMAT_ARGB8888,
|
|
|
- SDL_TEXTUREACCESS_STREAMING,
|
|
|
- windowWidth, windowHeight);
|
|
|
+ frameBufferTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, windowWidth,
|
|
|
+ windowHeight);
|
|
|
if (frameBufferTexture == NULL)
|
|
|
{
|
|
|
log(TLOG_PANIC, NULL, "SDL Texture creation error: %s", SDL_GetError());
|
|
@@ -107,18 +43,17 @@ void processInput()
|
|
|
SDL_Event event;
|
|
|
SDL_PollEvent(&event);
|
|
|
|
|
|
- switch(event.type)
|
|
|
+ switch (event.type)
|
|
|
{
|
|
|
- case SDL_QUIT:
|
|
|
- isRunning = false;
|
|
|
+ case SDL_QUIT:isRunning = false;
|
|
|
break;
|
|
|
|
|
|
- case SDL_KEYDOWN:
|
|
|
- if (event.key.keysym.sym == SDLK_ESCAPE)
|
|
|
- {
|
|
|
- isRunning = false;
|
|
|
- }
|
|
|
- break;
|
|
|
+ case SDL_KEYDOWN:
|
|
|
+ if (event.key.keysym.sym == SDLK_ESCAPE)
|
|
|
+ {
|
|
|
+ isRunning = false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
@@ -131,52 +66,6 @@ void update()
|
|
|
|
|
|
}
|
|
|
|
|
|
-void clearFrameBuffer(uint32_t colour)
|
|
|
-{
|
|
|
- int x, y;
|
|
|
- for(y = 0; y < windowHeight; y++)
|
|
|
- {
|
|
|
- for(x = 0; x < windowWidth; x++)
|
|
|
- {
|
|
|
- frameBuffer[x + (y * windowWidth)] = colour;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void drawGrid(int spacing, uint32_t colour)
|
|
|
-{
|
|
|
- int x, y;
|
|
|
- for(y = 0; y < windowHeight; y++)
|
|
|
- {
|
|
|
- for(x = 0; x < windowWidth; x++)
|
|
|
- {
|
|
|
- if (((x % spacing) == 0) || ((y % spacing) == 0))
|
|
|
- {
|
|
|
- frameBuffer[x + (y * windowWidth)] = colour;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void drawRectangle(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t colour)
|
|
|
-{
|
|
|
- uint32_t i, j;
|
|
|
-
|
|
|
- for(j = 0; j < h; j++)
|
|
|
- {
|
|
|
- for(i = 0; i < w; i++)
|
|
|
- {
|
|
|
- frameBuffer[i + x + ((j + y) * windowWidth)] = colour;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-void renderFrameBuffer()
|
|
|
-{
|
|
|
- SDL_UpdateTexture(frameBufferTexture, NULL, frameBuffer, windowWidth * sizeof(uint32_t));
|
|
|
- SDL_RenderCopy(renderer, frameBufferTexture, NULL, NULL);
|
|
|
-}
|
|
|
-
|
|
|
void render()
|
|
|
{
|
|
|
SDL_SetRenderDrawColor(renderer, 255, 64, 13, 255);
|
|
@@ -188,23 +77,10 @@ void render()
|
|
|
|
|
|
renderFrameBuffer();
|
|
|
clearFrameBuffer(0xFF000000);
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
SDL_RenderPresent(renderer);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-void destroy_window()
|
|
|
-{
|
|
|
- if (frameBuffer != NULL)
|
|
|
- {
|
|
|
- free(frameBuffer);
|
|
|
- }
|
|
|
- SDL_DestroyRenderer(renderer);
|
|
|
- SDL_DestroyWindow(window);
|
|
|
- SDL_Quit();
|
|
|
-}
|
|
|
-
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
int param_i;
|
|
@@ -213,18 +89,18 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
log(TLOG_ALWAYS, NULL, "Booting 3D Engine (version %s)!", VERSION);
|
|
|
|
|
|
- for (param_i = 1 ; (param_i < argc) && (argv[param_i][0] == '-'); param_i++)
|
|
|
+ for (param_i = 1 ; (param_i < argc) && (argv[param_i][0] == '-') ; param_i++)
|
|
|
{
|
|
|
switch (argv[param_i][1])
|
|
|
{
|
|
|
- default: exit(-1); /* Option not recognized */
|
|
|
- case 'f': fullScreen = true; break;
|
|
|
- case 'w': windowWidth = atoi(argv[++param_i]); break;
|
|
|
- case 'h': windowHeight = atoi(argv[++param_i]); break;
|
|
|
+ default: exit(-1); /* Option not recognized */
|
|
|
+ case 'f': fullScreen = true; break;
|
|
|
+ case 'w': windowWidth = atoi(argv[++param_i]);
|
|
|
+ case 'h': windowHeight = atoi(argv[++param_i]); break;
|
|
|
#ifdef DYNA_LOG_LEVEL
|
|
|
- case 'l': MAX_DEBUG_LEVEL = atoi(argv[++param_i]); break;
|
|
|
+ case 'l': MAX_DEBUG_LEVEL = atoi(argv[++param_i]); break;
|
|
|
#endif
|
|
|
- case '-': goto no_more_params;
|
|
|
+ case '-': goto no_more_params; /* Could use break, but this is more clear */
|
|
|
}
|
|
|
}
|
|
|
no_more_params:
|
|
@@ -233,7 +109,7 @@ no_more_params:
|
|
|
|
|
|
setup();
|
|
|
|
|
|
- while(isRunning)
|
|
|
+ while (isRunning)
|
|
|
{
|
|
|
processInput();
|
|
|
update();
|