bit of src tree shuffling. main.cpp to be replaced with test programs
full disclosure: i'm a bit unsure of what is the best way to do this at this point in time. the end goal with this project is that it becomes a library to be used by other apps (of course), but need tests to test various library functionality. unsure how best to organize this with cmake (and since i'm using clion, i kind of would prefer it works nicely and integrated with the ide...). i figure this is going to be a trial and error approach that will evolve over the next while
This commit is contained in:
parent
05f68bc409
commit
648832d939
|
@ -1,21 +1,20 @@
|
|||
cmake_minimum_required(VERSION 2.8.4)
|
||||
|
||||
set(PROJECT_NAME SoftwareRasterizer)
|
||||
set(PROJECT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
project(SoftwareRasterizer)
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SRC_DIR}/cmake")
|
||||
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(TESTS_DIR "${ROOT_DIR}/test")
|
||||
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${ROOT_DIR}/cmake")
|
||||
find_package(SDL2 REQUIRED)
|
||||
|
||||
file(GLOB_RECURSE SOURCE_FILES "."
|
||||
"${PROJECT_SRC_DIR}/src/*.cpp"
|
||||
"${PROJECT_SRC_DIR}/src/*.c"
|
||||
"${PROJECT_SRC_DIR}/src/*.h"
|
||||
"${PROJECT_SRC_DIR}/include/*.h"
|
||||
file(GLOB_RECURSE LIB_SRC_FILES "."
|
||||
"${ROOT_DIR}/src/*.cpp"
|
||||
"${ROOT_DIR}/src/*.c"
|
||||
"${ROOT_DIR}/src/*.h"
|
||||
"${ROOT_DIR}/include/*.h"
|
||||
)
|
||||
include_directories(${SDL2_INCLUDE_DIR} "${PROJECT_SRC_DIR}/include")
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARY})
|
||||
include_directories(${SDL2_INCLUDE_DIR} "${ROOT_DIR}/include")
|
||||
|
||||
add_executable("test_wm" "${TESTS_DIR}/test_wm.c" ${LIB_SRC_FILES})
|
||||
target_link_libraries("test_wm" ${SDL2_LIBRARY})
|
||||
|
|
14
include/vm/vm.h
Normal file
14
include/vm/vm.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vm/vm_stdinc.h"
|
||||
#include "vm/vm_log.h"
|
||||
#include "vm/vm_window.h"
|
||||
#include "vm/vm_input.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -4,8 +4,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vm_stdinc.h"
|
||||
#include "vm_input_codes.h"
|
||||
#include "vm/vm_stdinc.h"
|
||||
#include "vm/vm_input_codes.h"
|
||||
#include "SDL.h"
|
||||
|
||||
bool input_init();
|
|
@ -4,7 +4,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vm_stdinc.h"
|
||||
#include "vm/vm_stdinc.h"
|
||||
|
||||
void log_init();
|
||||
void log_end();
|
|
@ -4,7 +4,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vm_stdinc.h"
|
||||
#include "vm/vm_stdinc.h"
|
||||
#include "SDL.h"
|
||||
|
||||
typedef struct {
|
69
src/main.cpp
69
src/main.cpp
|
@ -1,69 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <fbgfx/surface.h>
|
||||
#include "vm/vm.h"
|
||||
#include "fbgfx/surface.h"
|
||||
#include "fbgfx/clipping.h"
|
||||
#include "assets/image.h"
|
||||
#include "vm/vm_window.h"
|
||||
|
||||
static inline double get_seconds() {
|
||||
return (double)clock() / CLOCKS_PER_SEC;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
log_init();
|
||||
input_init();
|
||||
WINDOW *window = window_init("Rasterizer Test", 1280, 960, 320, 240);
|
||||
if (!window)
|
||||
return 1;
|
||||
|
||||
SURFACE *sprite = image_load_file("/Users/gered/resources/grass01.bmp");
|
||||
SURFACE *sprite2 = surface_create(16, 16, SURFACE_FORMAT_ALPHA, SURFACE_FLAGS_NONE);
|
||||
surface_clear(sprite2, color_create_rgba(0, 0, 0, 0));
|
||||
surface_rect_filled(sprite2, 4, 4, 11, 11, color_create_rgba(0, 0, 0, 128));
|
||||
surface_line(sprite2, 0, 0, 15, 15, color_create_rgba(0, 0, 0, 255));
|
||||
|
||||
double before;
|
||||
double after;
|
||||
int i;
|
||||
|
||||
before = get_seconds();
|
||||
|
||||
for (i = 0; i < 500000; ++i) {
|
||||
surface_blit(sprite, window->surface, 0, 0);
|
||||
//surface_blit_blend(sprite, window->surface, 0, 0);
|
||||
}
|
||||
|
||||
after = get_seconds();
|
||||
|
||||
printf("time taken: %f\n", after - before);
|
||||
|
||||
while (true) {
|
||||
if (!window_do_events(window))
|
||||
break;
|
||||
if (input_is_key_pressed(KSYM_ESCAPE))
|
||||
break;
|
||||
|
||||
//surface_clear(window->surface, color_create_rgba(192, 192, 192, 255));
|
||||
int x, y;
|
||||
for (y = 0; y < window->surface->height; y += 16) {
|
||||
for (x = 0; x < window->surface->width; x += 16) {
|
||||
surface_blit(sprite, window->surface, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
surface_line(window->surface, window->viewport_width / 2, window->viewport_height / 2, input_get_mouse_x(), input_get_mouse_y(), COLOR_YELLOW);
|
||||
//surface_blit_tint(sprite, window->surface, INPUT_GetMouseX(), INPUT_GetMouseY(), COLOR_DOS_BROWN);
|
||||
surface_blit_blend(sprite2, window->surface, 0, 0);
|
||||
surface_blit_blend_tint(sprite2, window->surface, 16, 0, color_create_rgba(255, 0, 0, 64));
|
||||
|
||||
window_render(window);
|
||||
}
|
||||
|
||||
window_destroy(window);
|
||||
input_destroy();
|
||||
log_end();
|
||||
|
||||
return 0;
|
||||
}
|
14
src/vm/vm.h
14
src/vm/vm.h
|
@ -1,14 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "vm_stdinc.h"
|
||||
#include "vm_log.h"
|
||||
#include "vm_window.h"
|
||||
#include "vm_input.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
#include "vm_input.h"
|
||||
#include "vm_log.h"
|
||||
#include "vm/vm_input.h"
|
||||
#include "vm/vm_log.h"
|
||||
#include <string.h>
|
||||
|
||||
const int MAX_KEYS = SDL_NUM_SCANCODES;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include "vm_log.h"
|
||||
#include "vm/vm_log.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "vm_window.h"
|
||||
#include "vm_log.h"
|
||||
#include "vm_input.h"
|
||||
#include "vm/vm_window.h"
|
||||
#include "vm/vm_log.h"
|
||||
#include "vm/vm_input.h"
|
||||
#include "fbgfx/surface.h"
|
||||
|
||||
static SDL_Texture*create_texture(SDL_Renderer *renderer, int width, int height) {
|
||||
|
|
26
test/test_wm.c
Normal file
26
test/test_wm.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include "vm/vm.h"
|
||||
#include <fbgfx/surface.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
log_init();
|
||||
input_init();
|
||||
WINDOW *window = window_init("Rasterizer Test", 1280, 960, 320, 240);
|
||||
if (!window)
|
||||
return 1;
|
||||
|
||||
while (true) {
|
||||
if (!window_do_events(window))
|
||||
break;
|
||||
if (input_is_key_down(KSYM_ESCAPE))
|
||||
break;
|
||||
|
||||
window_render(window);
|
||||
}
|
||||
|
||||
window_destroy(window);
|
||||
input_destroy();
|
||||
log_end();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in a new issue