Changeset 676


Ignore:
Timestamp:
Jul 28, 2015, 6:02:28 PM (9 years ago)
Author:
guerin
Message:

raycast: load textures from misc/

Location:
soft/giet_vm/applications/raycast
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • soft/giet_vm/applications/raycast/disp.c

    r673 r676  
    33#include <stdio.h>
    44#include <stdlib.h>
     5#include <malloc.h>
    56#include <math.h>
    67#include <hard_config.h>
    7 
    8 #ifdef USE_TEXTURES
    9 #include "res/rock_tex.h"
    10 #include "res/door_tex.h"
    11 #include "res/handle_tex.h"
    12 #include "res/wood_tex.h"
    13 #endif
    148
    159#define FIELD_OF_VIEW   (70.f * M_PI / 180.f)   // Camera field of view
     
    2620unsigned int  cur_buf;
    2721
    28 #ifdef USE_TEXTURES
    2922// Textures indexed by block number
    30 static uint16_t *g_tex[] =
     23static unsigned char *g_tex[] =
    3124{
    3225    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_data
     26    NULL, // rock
     27    NULL, // door
     28    NULL, // handle
     29    NULL, // wood
    3730};
    38 #endif
    3931
    4032// Local functions
     
    6456
    6557    // Wall
    66 #ifdef USE_TEXTURES
    67     uint16_t *tex = g_tex[type];
     58    unsigned char *tex = g_tex[type];
    6859
    6960    if (tex) {
    7061        // Draw a texture slice
     62        dispDrawColumn(x,
     63               (FBUF_Y_SIZE - height) / 2,
     64               (FBUF_Y_SIZE + height) / 2,
     65               (x % 2 ? 0xAF : 0x7F));
    7166        /*Kentec320x240x16_SSD2119TexDrawV(
    7267            NULL, x,
     
    7671    }
    7772    else {
    78 #endif
    7973        // Draw a solid color slice
    8074        dispDrawColumn(x,
     
    8276                       (FBUF_Y_SIZE + height) / 2,
    8377                       0xFF);
    84 #ifdef USE_TEXTURES
    85     }
    86 #endif
     78    }
    8779
    8880    // Floor
     
    165157}
    166158
     159unsigned 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
    167178// Exported functions
    168179
    169180void dispInit()
    170181{
     182    // initialize framebuffer
    171183    giet_fbf_cma_alloc();
    172184    giet_fbf_cma_init_buf(buf0, buf1, sts0, sts1);
    173185    giet_fbf_cma_start(FBUF_X_SIZE * FBUF_Y_SIZE);
    174186
     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
    175193        cur_buf = 0;
    176194}
  • soft/giet_vm/applications/raycast/main.c

    r673 r676  
    22#include "disp.h"
    33#include <stdio.h>
     4#include <malloc.h>
    45
    56// Exported functions
     
    1011        giet_tty_printf("[RAYCAST] entering main()\n");
    1112
     13        heap_init(0, 0);
    1214        dispInit();
    1315
  • soft/giet_vm/applications/raycast/raycast.py

    r673 r676  
    3030
    3131    heap_base  = 0x60000000
    32     heap_size  = 0x00001000     # 4 Kbytes
     32    heap_size  = 0x00008000     # 32 Kbytes
    3333
    3434    # create vspace
Note: See TracChangeset for help on using the changeset viewer.