Exemple #1
0
void load_resources() {
	printf("load_resources():\n");
	
	char *path = malloc(strlen(get_prefix())+32);
	
	if(!(resources.state & RS_GfxLoaded)) {
		printf("- textures:\n");
		strcpy(path, get_prefix());
		strcat(path, "gfx");
		recurse_dir(path);
		
		resources.state |= RS_GfxLoaded;
	}
	
	if(!tconfig.intval[NO_AUDIO] && !(resources.state & RS_SfxLoaded)) {
		printf("- sounds:\n");
		
		alGenSources(SNDSRC_COUNT, resources.sndsrc);
		strcpy(path, get_prefix());
		strcat(path, "sfx");
		recurse_dir(path);
		
		resources.state |= RS_SfxLoaded;
	}
	
	if(!tconfig.intval[NO_SHADER] && !(resources.state & RS_ShaderLoaded)) {
		printf("- shader:\n");
		strcpy(path, get_prefix());
		strcat(path, "shader");
		recurse_dir(path);
		
		strcpy(path, get_prefix());
		strcat(path, "shader/laser_snippets");
		
		if(tgl_ext[TGLEXT_draw_instanced])
			load_shader_snippets(path, "laser_");
		
		printf("init_fbo():\n");
		init_fbo(&resources.fbg[0]);
		init_fbo(&resources.fbg[1]);
		init_fbo(&resources.fsec);
		printf("-- finished\n");
		
		resources.state |= RS_ShaderLoaded;
	}
	
	if(!(resources.state & RS_ModelsLoaded)) {
		printf("- models:\n");
		strcpy(path, get_prefix());
		strcat(path, "models");
		recurse_dir(path);
		
		resources.state |= RS_ModelsLoaded;
	}	
}
void RenderSystem::v_Init()
{
	init_device();
	init_camera();
	init_object();
	init_fbo();
}
Exemple #3
0
void init_gl(Scene *s)
{
  GLint ntexu, ntexc;

  if( glewInit() != GLEW_OK ) 
    { printf( "[error] %s\n", glewGetErrorString( glewInit() ) ); return; }

  glGetIntegerv(GL_MAX_TEXTURE_COORDS, &ntexc);
  glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &ntexu);
  max_textures_gl = MAX(ntexc, ntexu) - 1;

  glClearColor( 0, 0, 0, 1);
  glEnable(GL_DEPTH_TEST);
  glShadeModel(GL_SMOOTH);

  if (render_to_fbo)
    init_fbo(s);
  
  st_cleanup();
}
	void CamaraLucida::init(string kinect_calibration_filename,
							string proj_calibration_filename,
							string xml_config_filename,
							cml::Mesh *mesh,
							int tex_width, int tex_height, 
							int tex_num_samples)
	{
		this->mesh = mesh;
		
		coord_sys = mesh->coord_sys();
		
		init_cml(kinect_calibration_filename, 
				 proj_calibration_filename,
				 xml_config_filename);
				
		if (mesh->is_render_enabled())
		{
			init_fbo(tex_width, tex_height, tex_num_samples);
		}
		
		mesh->init(&xml_config, &calib, tex_width, tex_height);
	}
void opengl_init(int w, int h)
{
	/* init statue *********************************************************************************/
	CLoad3DS g_Load3ds;	
	t3DModel g_3DModel;
	
	shader_loader vs,ps;

	init_fbo(render_fbo, render_rt, true);
	init_fbo(blur_fbo, blur_rt, true);

	if(model_mesh.program == NULL)
	{
		LOGI("begin load shader");

		model_mesh.program = new shader_program;
		if(!model_mesh.program->build(vs.load_shader_source("media/model.vs"),ps.load_shader_source("media/model.ps")))
		{
			LOGI("build shader failed");
			return;
		}
	
		model_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(model_mesh.program->get_program(),"rm_Vertex");
		model_mesh.attribute_locations[static_mesh::NORMAL] = glGetAttribLocation(model_mesh.program->get_program(),"rm_Normal");
		model_mesh.attribute_locations[static_mesh::TEXCOORD] = glGetAttribLocation(model_mesh.program->get_program(),"rm_TexCoord0");

		LOGI("begin to load 3ds file");
		g_Load3ds.Import3DS(&g_3DModel, "media/Radeon.3ds");
		LOGI("load 3ds end");

		t3DObject* p = &g_3DModel.pObject[0];
LOGI("---------- 0");
		model_mesh.loc_view_matrix = glGetUniformLocation(model_mesh.program->get_program(), "view_matrix");
		model_mesh.loc_view_proj_matrix = glGetUniformLocation(model_mesh.program->get_program(), "view_proj_matrix");
		model_mesh.texs_locs[0] = glGetUniformLocation(model_mesh.program->get_program(), "base");
LOGI("---------- 1");
		model_mesh.texs_idxs[0] = create_texture("media/Wood.tga");

LOGI("---------- 2");
		glGenBuffers(4, model_mesh.attribute_vbos);
LOGI("---------- 3");
		glBindBuffer(GL_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::POSITION]);
		glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pVerts[0].x), GL_STATIC_DRAW);
LOGI("---------- 4");
		glBindBuffer(GL_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::NORMAL]);
		glBufferData(GL_ARRAY_BUFFER, 4*3*p->numOfVerts, &(p->pNormals[0].x), GL_STATIC_DRAW);

		glBindBuffer(GL_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::TEXCOORD]);
		glBufferData(GL_ARRAY_BUFFER, 4*2*p->numOfVerts, &(p->pTexVerts[0].x), GL_STATIC_DRAW);

		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, model_mesh.attribute_vbos[static_mesh::INDEX]);
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, 2*3*p->numOfFaces, &(p->pFaces[0].vertIndex[0]), GL_STATIC_DRAW);
LOGI("---------- 5");
		model_mesh.num_faces = p->numOfFaces;
	}

	/* init background *********************************************************************************/
	
	if(blur_mesh.program == NULL)
	{
		float *pos_data;
		GLushort *inds;
		GLuint num_ves;

		blur_mesh.program = new shader_program;
		if(!blur_mesh.program->build(vs.load_shader_source("media/quad.vs"),ps.load_shader_source("media/quad.ps")))
		{
			LOGI("build shader failed");
			return;
		}

		blur_mesh.texs_idxs[0] = render_rt;
		blur_mesh.texs_locs[0] = glGetUniformLocation(blur_mesh.program->get_program(), "RT");

		shape::create_plane(1, &pos_data, NULL, NULL, &inds, num_ves);

//		blur_mesh.loc_view_proj_matrix = glGetUniformLocation(blur_mesh.program->get_program(), "view_proj_matrix");
		
		blur_mesh.attribute_locations[static_mesh::POSITION] = glGetAttribLocation(blur_mesh.program->get_program(),"rm_Vertex");

		glGenBuffers(1, &blur_mesh.attribute_vbos[static_mesh::POSITION]);
		glGenBuffers(1, &blur_mesh.attribute_vbos[static_mesh::INDEX]);

		glBindBuffer(GL_ARRAY_BUFFER, blur_mesh.attribute_vbos[static_mesh::POSITION]);
		glBufferData(GL_ARRAY_BUFFER, num_ves*4*3, pos_data, GL_STATIC_DRAW);

		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, blur_mesh.attribute_vbos[static_mesh::INDEX]);
		glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6*2*3, inds, GL_STATIC_DRAW);

		blur_mesh.num_faces = 6;

		delete []pos_data;
		delete []inds;
	}

	if(combine_mesh.program == NULL)
	{
		float *pos_data;
		GLushort *inds;
		GLuint num_ves;

		combine_mesh = blur_mesh;

		combine_mesh.program = new shader_program;
		if(!combine_mesh.program->build(vs.load_shader_source("media/combine.vs"),ps.load_shader_source("media/combine.ps")))
		{
			LOGI("build shader failed");
			return;
		}

		combine_mesh.texs_idxs[0] = render_rt;
		combine_mesh.texs_locs[0] = glGetUniformLocation(combine_mesh.program->get_program(), "RT");

		combine_mesh.texs_idxs[1] = blur_rt;
		combine_mesh.texs_locs[1] = glGetUniformLocation(combine_mesh.program->get_program(), "Blur1");

		

	}

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	
	width = w;
	height = h;
	
	quad_proj_matrix.perspective(60, (float)w/h, 1.0f,3000.0f);
}
int mainloop(void*)
{
	int drawchange = 0; int refreshdelay[2] = {33, 33}; int rdelay = 33;
	Uint32 time1 = SDL_GetTicks(), time2 = SDL_GetTicks();
	float ts; int u; int i;
	
	if(!init_SDL(surface))
	{ fprintf(stderr, "SDL_OPENGL failed\n"); exit(1);}
	if(!initGL(w_width, w_height))
	{ fprintf(stderr, "OpenGL failed\n"); exit(1);}

	SDL_WM_SetCaption( "Tesseract", NULL );

	glPointSize(8.0f);

	resizewindow(1280, 1024); 

	load_textures();

	lbounds[0] = 10;
	ts = lbounds[0];

	q = (Quaternion*)(malloc(9999999*sizeof(Quaternion)));
	qbuffer = (Quaternion*)(malloc(9999*sizeof(Quaternion)));
	quatnum = 0;

//	quatnum += construct_tesseract(1,1,1,1, 0, 0, 0, 1,quatnum, 0.5);
playerpost.set(0,0,0,0);
	float acc = fack;

	float spp[18] = { 
		0,
		0, 
		(GLfloat)iterations, // 255 iterations
		0.35f,
		0,
		F_QUATMANDEL,
		-acc+playerpost.a,
		acc+playerpost.a,
		-acc+playerpost.b,
		acc+playerpost.b,
		-acc+playerpost.c,
		acc+playerpost.c,
		-acc+playerpost.d,
		acc+playerpost.d,
		acc,
		zoom2,
		tesseract,
		simplex
		};

	if(points)
		{
			quatnum = calc_fractal(spp, q);
		}
	else
		quatnum += construct_tesseract(1,1,1,1, 0, 0, 0, 0,quatnum, 0.5);

	bquat = quatnum; 
	t_size = quatnum;
/*
	quatnum += construct_tesseract(1,1,1,1, -ts,  ts,  ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts, -ts,  ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts,  ts, -ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts,  ts,  ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts, -ts, -ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts, -ts,  ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts,  ts, -ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts, -ts, -ts,  ts,quatnum, 0.5);

	quatnum += construct_tesseract(1,1,1,1, -ts,  ts,  ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts, -ts,  ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts,  ts, -ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts,  ts,  ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts, -ts, -ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts, -ts,  ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts,  ts, -ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts, -ts, -ts,  -ts,quatnum, 0.5);
*/

	freequat = quatnum; 
//	quatnum += construct_tesseract(1,1,1,1, 0,  0, 0, 0,quatnum, 0.5);

/*
	for(u = 4; u <= 8; u+=2)
	quatnum += construct_tesseract(1,1,1,1, 0,  0, 0, -(5-u*4),quatnum, 1.75);

	for(u = 4; u <= 8; u+=2)
	quatnum += construct_tesseract(1,1,1,1, 0,  0, -(5-u*4), 0,quatnum, 1.75);

	for(u = 4; u <= 8; u+=2)
	quatnum += construct_tesseract(1,1,1,1, 0, -(5-u*4), 0, 0,quatnum, 1.75);

	for(u = 4; u <= 8; u+=2)
	quatnum += construct_tesseract(1,1,1,1, -(5-u*4),  0,  0, 0,quatnum, 1.75);

*/

	movquat = quatnum;

/*
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.8);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 1.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);

	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
*/
	maxquat = quatnum;

	int yy;
	printf("quatnum: %d\n", quatnum);

//	for(u = 0; u < quatnum; u++)
//		qo[u] = q[u];

	playerpos.set(0,0,0,0);
	playerpost.set(0,0,0,0);
	padd.set(0,0,0,0);
	ptemp.set(0,0,0,0);
	ptemp2.set(0,0,0,0);

			randreinit();

	init_fbo(0);	
	init_fbo(1);	
	init_fbo(2);
	
	init_fbo(3);	

	for(i = 0; i < quatnum/4; i++)
	{
		zposbuf[i] = get_zposbuf(i);
		zposbufi[i] = i;
	}

	while(!done)
	{
		framecounter++;
		if(framecounter > 4294967000UL) framecounter = 0;
		drawchange = keylistener();
		SDL_Delay(rdelay*0.5);
		if(!(framecounter%5))
		{
//			printf("Delay: %d\n", rdelay);
			time1 = SDL_GetTicks();
			refreshdelay[framecounter%2] = 
				1000/((((int)(time1-time2)) > 0)
				? (int)(time1-time2) : 1000 );
			time2 = time1;
			if(abs(refreshdelay[framecounter%2]
			- refreshdelay[(framecounter-1)%2])
			>= 2)
			{ 
				rdelay = (refreshdelay[framecounter%2]
				       + refreshdelay[(framecounter-1)%2])/2; 
				rdelay -= 16;
				if(rdelay <= 0) rdelay = 0;
				rdelay = 33;
			}
		}
		if(!(framecounter%((int)(33*20))))
			randreinit();		
		drawGLscene();
	}
	printf("Quit called, cleaning up\n");
	SDL_Quit(); 

	return(0);
}
Exemple #7
0
	void MeshLoad::init()
	{
		init_buffer();
		init_shader();
		init_fbo();
	}