Changeset 676 for soft/giet_vm/applications/raycast/disp.c
- Timestamp:
- Jul 28, 2015, 6:02:28 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/raycast/disp.c
r673 r676 3 3 #include <stdio.h> 4 4 #include <stdlib.h> 5 #include <malloc.h> 5 6 #include <math.h> 6 7 #include <hard_config.h> 7 8 #ifdef USE_TEXTURES9 #include "res/rock_tex.h"10 #include "res/door_tex.h"11 #include "res/handle_tex.h"12 #include "res/wood_tex.h"13 #endif14 8 15 9 #define FIELD_OF_VIEW (70.f * M_PI / 180.f) // Camera field of view … … 26 20 unsigned int cur_buf; 27 21 28 #ifdef USE_TEXTURES29 22 // Textures indexed by block number 30 static u int16_t*g_tex[] =23 static unsigned char *g_tex[] = 31 24 { 32 25 NULL, // 0 33 (uint16_t*)&rock_tex_data,34 (uint16_t*)&door_tex_data,35 (uint16_t*)&handle_tex_data,36 (uint16_t*)&wood_tex_data26 NULL, // rock 27 NULL, // door 28 NULL, // handle 29 NULL, // wood 37 30 }; 38 #endif39 31 40 32 // Local functions … … 64 56 65 57 // Wall 66 #ifdef USE_TEXTURES 67 uint16_t *tex = g_tex[type]; 58 unsigned char *tex = g_tex[type]; 68 59 69 60 if (tex) { 70 61 // Draw a texture slice 62 dispDrawColumn(x, 63 (FBUF_Y_SIZE - height) / 2, 64 (FBUF_Y_SIZE + height) / 2, 65 (x % 2 ? 0xAF : 0x7F)); 71 66 /*Kentec320x240x16_SSD2119TexDrawV( 72 67 NULL, x, … … 76 71 } 77 72 else { 78 #endif79 73 // Draw a solid color slice 80 74 dispDrawColumn(x, … … 82 76 (FBUF_Y_SIZE + height) / 2, 83 77 0xFF); 84 #ifdef USE_TEXTURES 85 } 86 #endif 78 } 87 79 88 80 // Floor … … 165 157 } 166 158 159 unsigned char *loadTexture(char *path) 160 { 161 int fd; 162 unsigned char *tex; 163 164 tex = malloc(TEX_SIZE * TEX_SIZE); 165 fd = giet_fat_open(path, O_RDONLY); 166 if (fd < 0) { 167 free(tex); 168 return NULL; 169 } 170 171 giet_fat_read(fd, g_tex[1], TEX_SIZE * TEX_SIZE); 172 giet_fat_close(fd); 173 giet_tty_printf("[RAYCAST] loaded tex %s\n", path); 174 175 return tex; 176 } 177 167 178 // Exported functions 168 179 169 180 void dispInit() 170 181 { 182 // initialize framebuffer 171 183 giet_fbf_cma_alloc(); 172 184 giet_fbf_cma_init_buf(buf0, buf1, sts0, sts1); 173 185 giet_fbf_cma_start(FBUF_X_SIZE * FBUF_Y_SIZE); 174 186 187 // load textures 188 g_tex[1] = loadTexture("misc/rock_32.raw"); 189 g_tex[2] = loadTexture("misc/door_32.raw"); 190 g_tex[3] = loadTexture("misc/handle_32.raw"); 191 g_tex[4] = loadTexture("misc/wood_32.raw"); 192 175 193 cur_buf = 0; 176 194 }
Note: See TracChangeset
for help on using the changeset viewer.