|
@@ -18,7 +18,12 @@
|
|
|
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()
|
|
|
{
|
|
@@ -30,15 +35,19 @@ bool initialiseWindow()
|
|
|
goto exit;
|
|
|
}
|
|
|
|
|
|
+ log(TLOG_DEBUG, NULL, "SDL properly initialised!");
|
|
|
+
|
|
|
window = SDL_CreateWindow(NULL,
|
|
|
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
|
|
- 800, 600,
|
|
|
+ windowWidth, windowHeight,
|
|
|
SDL_WINDOW_BORDERLESS);
|
|
|
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)
|
|
@@ -46,12 +55,107 @@ bool initialiseWindow()
|
|
|
log(TLOG_PANIC, NULL, "SDL Renderer creation error: %s", SDL_GetError());
|
|
|
goto exit;
|
|
|
}
|
|
|
+ log(TLOG_DEBUG, NULL, "SDL Renderer created!");
|
|
|
|
|
|
ret = true;
|
|
|
exit:
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+void setup()
|
|
|
+{
|
|
|
+ frameBuffer = (uint32_t *)calloc(windowWidth * windowHeight, sizeof(uint32_t));
|
|
|
+ if (!frameBuffer)
|
|
|
+ {
|
|
|
+ log(TLOG_PANIC, NULL, "Memory allocation error.");
|
|
|
+ goto exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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());
|
|
|
+ goto exit;
|
|
|
+ }
|
|
|
+
|
|
|
+exit:
|
|
|
+ return;
|
|
|
+}
|
|
|
+
|
|
|
+void processInput()
|
|
|
+{
|
|
|
+ SDL_Event event;
|
|
|
+ SDL_PollEvent(&event);
|
|
|
+
|
|
|
+ switch(event.type)
|
|
|
+ {
|
|
|
+ case SDL_QUIT:
|
|
|
+ isRunning = false;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case SDL_KEYDOWN:
|
|
|
+ if (event.key.keysym.sym == SDLK_ESCAPE)
|
|
|
+ {
|
|
|
+ isRunning = false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+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 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);
|
|
|
+ SDL_RenderClear(renderer);
|
|
|
+
|
|
|
+ renderFrameBuffer();
|
|
|
+ clearFrameBuffer(0xFFFFFF00);
|
|
|
+
|
|
|
+
|
|
|
+ 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[])
|
|
|
{
|
|
|
MAX_DEBUG_LEVEL = TLOG_DEBUG;
|
|
@@ -59,5 +163,16 @@ int main(int argc, char *argv[])
|
|
|
log(TLOG_ALWAYS, NULL, "Booting 3D Engine (version %s)!", VERSION);
|
|
|
isRunning = initialiseWindow();
|
|
|
|
|
|
+ setup();
|
|
|
+
|
|
|
+ while(isRunning)
|
|
|
+ {
|
|
|
+ processInput();
|
|
|
+ update();
|
|
|
+ render();
|
|
|
+ }
|
|
|
+
|
|
|
+ destroy_window();
|
|
|
+
|
|
|
return 0;
|
|
|
}
|