예제 #1
0
파일: vbo.c 프로젝트: piaopolar/taisei
void init_quadvbo(void) {
	Vertex verts[] = {
		{{-0.5,-0.5,0},{0,0,1},0,0},
		{{-0.5,0.5,0},{0,0,1},0,1},
		{{0.5,0.5,0},{0,0,1},1,1},
		{{0.5,-0.5,0},{0,0,1},1,0},
		
		// Alternative quad for FBO		
		{{-0.5,-0.5,0},{0,0,1},0,1},
		{{-0.5,0.5,0},{0,0,1},0,0},
		{{0.5,0.5,0},{0,0,1},1,0},
		{{0.5,-0.5,0},{0,0,1},1,1}		
	};
	
	init_vbo(&_vbo, VBO_SIZE);
	glBindBuffer(GL_ARRAY_BUFFER, _vbo.vbo);
	
	vbo_add_verts(&_vbo, verts, 8);
}
예제 #2
0
파일: model.c 프로젝트: miton/taisei
Model *load_model(char *filename) {
	Model *m = create_element((void **)&resources.models, sizeof(Model));
	
	ObjFileData data;
	unsigned int i;
	
	Vertex *verts;
	unsigned int ioffset = _vbo.offset;
	
	char *beg = strstr(filename, "models/") + 7;
	char *end = strrchr(filename, '.');
	
	m->name = malloc(end - beg + 1);
	memset(m->name, 0, end-beg + 1);
	strncpy(m->name, beg, end-beg);
		
	
	parse_obj(filename, &data);
		
	m->fverts = data.fverts;
	m->indices = calloc(data.icount, sizeof(int));
	m->icount = data.icount;
	
	verts = calloc(data.icount, sizeof(Vertex));
	
	
	memset(verts, 0, data.icount*sizeof(Vertex));
	for(i = 0; i < data.icount; i++) {
		int xi, ni, ti;
		
		xi = data.indices[i][0]-1;
		if(xi < 0 || xi >= data.xcount)
			bad_reference_error(filename, "vertex", i);
		
		memcpy(verts[i].x, data.xs[xi], sizeof(Vector));
				
		if(data.tcount) {
			ti = data.indices[i][1]-1;
			if(ti < 0 || ti >= data.tcount)
				bad_reference_error(filename, "texcoord", i);
			
			verts[i].s = data.texcoords[ti][0];
			verts[i].t = data.texcoords[ti][1];
		}
		
		if(data.ncount) {
			ni = data.indices[i][2]-1;
			if(ni < 0 || ni >= data.ncount)
				bad_reference_error(filename, "normal", ni);
			
			memcpy(verts[i].n, data.normals[ni], sizeof(Vector));
		}
		
		m->indices[i] = i+ioffset;
	}
	
	vbo_add_verts(&_vbo, verts, data.icount);
	
	printf("-- loaded '%s' as '%s'\n", filename, m->name);
	
	free(verts);
	free(data.xs);
	free(data.normals);
	free(data.texcoords);
	free(data.indices);
	return m;
}