示例#1
0
void render_init(void)
{
   // @TODO: support non-DXT path
   char **files = stb_readdir_recursive("data", "*.crn");
   int i;

   camera_bounds[0][0] = - 0.75f;
   camera_bounds[0][1] = - 0.75f;
   camera_bounds[0][2] = - 4.25f;
   camera_bounds[1][0] = + 0.75f;
   camera_bounds[1][1] = + 0.75f;
   camera_bounds[1][2] = + 0.25f;

   init_chunk_caches();
   init_mesh_building();
   init_mesh_build_threads();
   s_init_physics_cache();

   glGenTextures(2, voxel_tex);

   glBindTexture(GL_TEXTURE_2D_ARRAY_EXT, voxel_tex[0]);

   for (i=0; i < 11; ++i) {
      glTexImage3DEXT(GL_TEXTURE_2D_ARRAY_EXT, i,
                         GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
                         1024>>i,1024>>i,128,0,
                         GL_RGBA,GL_UNSIGNED_BYTE,NULL);
   }

   #if 1
   for (i=0; i < sizeof(textures)/sizeof(textures[0]); ++i) {
      size_t len;
      char *filename = stb_sprintf("data/pixar/crn/%s.crn", textures[i].filename);
      uint8 *data = stb_file(filename, &len);
      load_crn_to_texture_array(i, data, len);
      free(data);
      texture_scales[i] = 1.0f/4;// textures[i].scale;
   }
   #endif

   // temporary hack:
   voxel_tex[1] = voxel_tex[0];

   init_voxel_render(voxel_tex);

   {
      char *frag[] = { dumb_fragment_shader, NULL };
      char error[1024];
      GLuint fragment;
      fragment = stbgl_compile_shader(STBGL_FRAGMENT_SHADER, frag, -1, error, sizeof(error));
      if (!fragment) {
         ods("oops");
         exit(0);
      }
      dumb_prog = stbgl_link_program(0, fragment, NULL, -1, error, sizeof(error));
      
   }

   #if 0
   {
      size_t len;
      unsigned char *data = stb_file(files[0], &len);
      glGenTextures(1, &debug_tex);
      glBindTexture(GL_TEXTURE_2D, debug_tex);
      load_crn_to_texture(data, len);
      free(data);
   }
   #endif
}
示例#2
0
文件: vfs.c 项目: timsjostrand/lodge
void vfs_mount(const char* dir)
{
	if (dir == NULL)
	{
		vfs_error("Mount directory is NULL\n");
		return;
	}

	char path[VFS_MOUNT_PATH_MAX];
	strcpy(path, dir);
	size_t pathlen = strlen(path);

	if (pathlen == 0)
	{
		vfs_error("Mount directory is of length 0\n");
		return;
	}

	if (path[pathlen - 1] == '\\' || path[pathlen - 1] == '/')
	{
		path[pathlen - 1] = '\0';
	}

	char** filenames = stb_readdir_recursive(path, NULL);

	if (filenames == NULL)
	{
		vfs_error("Could not read directory: %s\n", path);
		return;
	}

	int num_new_files = stb_arr_len(filenames);
	for (int i = 0; i < num_new_files; i++)
	{
		struct vfs_file new_file;
		strcpy(new_file.name, filenames[i]);
		strcpy(new_file.simplename, filenames[i] + strlen(path) + 1);

		int replaced = 0;
		for (int j = 0; j < vfs_global->file_count; j++)
		{
			if (strcmp(vfs_global->file_table[j].simplename, new_file.simplename) == 0)
			{
				stb_fclose(vfs_global->file_table[j].file, 0);
				free(vfs_global->file_table[j].data);

				strcpy(vfs_global->file_table[j].name, new_file.name);
				vfs_global->file_table[j].file = stb_fopen(vfs_global->file_table[j].name, "rb");
				vfs_global->file_table[j].lastChange = stb_ftimestamp(vfs_global->file_table[j].name);
				vfs_global->file_table[j].size = stb_filelen(vfs_global->file_table[j].file);
				vfs_global->file_table[j].data = malloc(vfs_global->file_table[j].size);
				fread(vfs_global->file_table[j].data, 1, vfs_global->file_table[j].size, vfs_global->file_table[j].file);
				stb_fclose(vfs_global->file_table[i].file, 0);

				replaced = 1;
				break;
			}
		}

		if (!replaced)
		{
			new_file.read_callbacks = 0;
			new_file.file = stb_fopen(new_file.name, "rb");
			new_file.lastChange = stb_ftimestamp(new_file.name);
			new_file.size = stb_filelen(new_file.file);
			new_file.data = malloc(new_file.size);
			fread(new_file.data, 1, new_file.size, new_file.file);
			stb_fclose(new_file.file, 0);

			vfs_global->file_table[vfs_global->file_count] = new_file;
			vfs_global->file_count++;
		}
	}
}