updated code
parent
0876d67d14
commit
f584672b2c
|
@ -1,4 +1,5 @@
|
||||||
#pebble
|
#pebble
|
||||||
|
/resources/data
|
||||||
/build
|
/build
|
||||||
.lock-waf_darwin_build
|
.lock-waf_darwin_build
|
||||||
|
|
||||||
|
|
10
appinfo.json
10
appinfo.json
|
@ -10,14 +10,14 @@
|
||||||
"resources": {
|
"resources": {
|
||||||
"media": [
|
"media": [
|
||||||
{
|
{
|
||||||
"file": "data/shading",
|
"file": "data/shading.bin",
|
||||||
"name": "SHADING_TEST",
|
"name": "SHADING",
|
||||||
"targetPlatforms": null,
|
"targetPlatforms": null,
|
||||||
"type": "raw"
|
"type": "raw"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"file": "data/testlut",
|
"file": "data/lut.bin",
|
||||||
"name": "MAP_TEST",
|
"name": "LUT",
|
||||||
"targetPlatforms": null,
|
"targetPlatforms": null,
|
||||||
"type": "raw"
|
"type": "raw"
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,6 @@
|
||||||
"uuid": "58059a20-c8c1-4a51-b99b-f0663e97ace8",
|
"uuid": "58059a20-c8c1-4a51-b99b-f0663e97ace8",
|
||||||
"versionLabel": "0.1",
|
"versionLabel": "0.1",
|
||||||
"watchapp": {
|
"watchapp": {
|
||||||
"watchface": true
|
"watchface": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
src/main.c
18
src/main.c
|
@ -45,7 +45,7 @@ typedef struct {
|
||||||
// global state
|
// global state
|
||||||
static State g;
|
static State g;
|
||||||
|
|
||||||
static bool debug = false;
|
static bool debug = true;
|
||||||
|
|
||||||
/************************************ UI **************************************/
|
/************************************ UI **************************************/
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ static void create_texture(State *state, Layer *layer, GContext *ctx) {
|
||||||
graphics_context_set_fill_color(ctx, GColorBlack);
|
graphics_context_set_fill_color(ctx, GColorBlack);
|
||||||
graphics_fill_circle(ctx, state->center, WHWIDTH/4);
|
graphics_fill_circle(ctx, state->center, WHWIDTH/4);
|
||||||
|
|
||||||
state->bgcolor = GColorIcterine; // background color for behind the objects
|
state->bgcolor = GColorShockingPink; // background color for behind the objects
|
||||||
|
|
||||||
// set up texture buffer
|
// set up texture buffer
|
||||||
state->texturesize = GSize(state->texturebounds.size.w, state->texturebounds.size.h);
|
state->texturesize = GSize(state->texturebounds.size.w, state->texturebounds.size.h);
|
||||||
|
@ -99,8 +99,8 @@ static void create_texture(State *state, Layer *layer, GContext *ctx) {
|
||||||
// release frame buffer
|
// release frame buffer
|
||||||
graphics_release_frame_buffer(ctx, tex_fb);
|
graphics_release_frame_buffer(ctx, tex_fb);
|
||||||
|
|
||||||
graphics_context_set_fill_color(ctx, GColorBlack);
|
/*graphics_context_set_fill_color(ctx, GColorBlack);
|
||||||
graphics_fill_rect(ctx, bounds, 0, GCornerNone);
|
graphics_fill_rect(ctx, bounds, 0, GCornerNone);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy_texture(State *state) {
|
static void destroy_texture(State *state) {
|
||||||
|
@ -115,12 +115,12 @@ static void render_slice(State *state, Layer *layer, GContext *ctx, GRect render
|
||||||
uint8_t (*texture_matrix)[state->texturesize.w] = (uint8_t (*)[state->texturesize.w]) gbitmap_get_data(state->texture);
|
uint8_t (*texture_matrix)[state->texturesize.w] = (uint8_t (*)[state->texturesize.w]) gbitmap_get_data(state->texture);
|
||||||
// START OF TEXTURE MAPPING
|
// START OF TEXTURE MAPPING
|
||||||
// load map parts
|
// load map parts
|
||||||
ResHandle lut_handle = resource_get_handle(RESOURCE_ID_MAP_TEST);
|
ResHandle lut_handle = resource_get_handle(RESOURCE_ID_LUT);
|
||||||
size_t lut_res_size = bounds.size.w*renderbounds.size.h*2;
|
size_t lut_res_size = bounds.size.w*renderbounds.size.h*2;
|
||||||
uint8_t *lut_buffer = (uint8_t*)malloc(lut_res_size);
|
uint8_t *lut_buffer = (uint8_t*)malloc(lut_res_size);
|
||||||
resource_load_byte_range(lut_handle, renderbounds.origin.y*bounds.size.w*2, lut_buffer, lut_res_size);
|
resource_load_byte_range(lut_handle, renderbounds.origin.y*bounds.size.w*2, lut_buffer, lut_res_size);
|
||||||
|
|
||||||
ResHandle shad_handle = resource_get_handle(RESOURCE_ID_SHADING_TEST);
|
ResHandle shad_handle = resource_get_handle(RESOURCE_ID_SHADING);
|
||||||
size_t shad_res_size = 144*renderbounds.size.h;
|
size_t shad_res_size = 144*renderbounds.size.h;
|
||||||
uint8_t *shad_buffer = (uint8_t*)malloc(shad_res_size);
|
uint8_t *shad_buffer = (uint8_t*)malloc(shad_res_size);
|
||||||
resource_load_byte_range(shad_handle, renderbounds.origin.y*bounds.size.w, shad_buffer, shad_res_size);
|
resource_load_byte_range(shad_handle, renderbounds.origin.y*bounds.size.w, shad_buffer, shad_res_size);
|
||||||
|
@ -139,7 +139,8 @@ static void render_slice(State *state, Layer *layer, GContext *ctx, GRect render
|
||||||
GBitmapDataRowInfo info = gbitmap_get_data_row_info(fb, y);
|
GBitmapDataRowInfo info = gbitmap_get_data_row_info(fb, y);
|
||||||
//APP_LOG(APP_LOG_LEVEL_DEBUG, "y %d x <= %d", y, info.max_x);
|
//APP_LOG(APP_LOG_LEVEL_DEBUG, "y %d x <= %d", y, info.max_x);
|
||||||
for(uint8_t x = info.min_x; x <= info.max_x; x++) {
|
for(uint8_t x = info.min_x; x <= info.max_x; x++) {
|
||||||
GColor fbpixel = state->bgcolor;
|
GColor fbpixel;
|
||||||
|
fbpixel.argb = info.data[x];
|
||||||
|
|
||||||
// convert to 24 bit color
|
// convert to 24 bit color
|
||||||
GColor32 newpixel;
|
GColor32 newpixel;
|
||||||
|
@ -149,13 +150,13 @@ static void render_slice(State *state, Layer *layer, GContext *ctx, GRect render
|
||||||
newpixel.a = 0xff;
|
newpixel.a = 0xff;
|
||||||
|
|
||||||
// render texture mapped object by looking up pixels in the lookup table
|
// render texture mapped object by looking up pixels in the lookup table
|
||||||
|
|
||||||
if (x >= mapbounds.origin.x && y >= mapbounds.origin.y && x < mapbounds.origin.x+mapbounds.size.w && y < mapbounds.origin.y+mapbounds.size.h) {
|
if (x >= mapbounds.origin.x && y >= mapbounds.origin.y && x < mapbounds.origin.x+mapbounds.size.w && y < mapbounds.origin.y+mapbounds.size.h) {
|
||||||
uint16_t surfindex = (x-mapbounds.origin.x)+((y-mapbounds.origin.y)*mapbounds.size.w);
|
uint16_t surfindex = (x-mapbounds.origin.x)+((y-mapbounds.origin.y)*mapbounds.size.w);
|
||||||
|
|
||||||
uint8_t xpos = lut_buffer[surfindex*2];
|
uint8_t xpos = lut_buffer[surfindex*2];
|
||||||
uint8_t ypos = lut_buffer[(surfindex*2)+1];
|
uint8_t ypos = lut_buffer[(surfindex*2)+1];
|
||||||
|
|
||||||
|
|
||||||
//APP_LOG(APP_LOG_LEVEL_DEBUG, "x %d - y %d", xpos, ypos);
|
//APP_LOG(APP_LOG_LEVEL_DEBUG, "x %d - y %d", xpos, ypos);
|
||||||
if (xpos > 0 || ypos > 0) {
|
if (xpos > 0 || ypos > 0) {
|
||||||
uint8_t texturexpos = xpos/2;
|
uint8_t texturexpos = xpos/2;
|
||||||
|
@ -192,7 +193,6 @@ static void render_slice(State *state, Layer *layer, GContext *ctx, GRect render
|
||||||
newpixel.b = (newpixel.b/DITHERFACTOR)*DITHERFACTOR;
|
newpixel.b = (newpixel.b/DITHERFACTOR)*DITHERFACTOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t specularmap = shad_buffer[surfindex];
|
uint8_t specularmap = shad_buffer[surfindex];
|
||||||
uint8_t shadowmap = (specularmap & 0b00001111)*16;
|
uint8_t shadowmap = (specularmap & 0b00001111)*16;
|
||||||
specularmap = ((specularmap & 0b11110000) >> 4)*16;
|
specularmap = ((specularmap & 0b11110000) >> 4)*16;
|
||||||
|
|
Loading…
Reference in New Issue