Esempio n. 1
0
font *
ttf_read_tga (fontp f, const char *name, int32_t pointsize)
{
    char filename[MAXSTR];
    uint32_t c;
    texp tex;

    if (pointsize < 0) {
        ERR("nutso font size %d", pointsize);
    }

    if (pointsize > 100) {
        ERR("nutso font size %d", pointsize);
    }

    /*
     * Read the glyph data.
     */
    snprintf(filename, sizeof(filename), "%s_pointsize%d.data",
             name, pointsize);

    const unsigned char *glyph_data = ramdisk_load(filename, 0);
    if (!glyph_data) {
        ERR("could not load font %s data", filename);
    }

    memcpy(f->glyphs, glyph_data, sizeof(f->glyphs));

    snprintf(filename, sizeof(filename), "%s_pointsize%u.tga",
             name, pointsize);

    tex = tex_load(filename,
                   filename /* to make unique for same point size */);
    if (!tex) {
        ERR("could not load font %s tex", filename);
    }

    for (c = TTF_GLYPH_MIN; c < TTF_GLYPH_MAX; c++) {
        f->tex[c].tex = tex_get_gl_binding(tex);
        f->tex[c].image = tex_get_surface(tex);
    }

    return (f);
}
Esempio n. 2
0
GuiDesc greed_gui_style(bool highres) {
	GuiDesc style;

	gui_tex = tex_load("greed_assets/gui_new.png");
	if(highres) {
		huge_font = font_load_ex("greed_assets/lucida_grande_60px.bft", 0.5f);
		big_font = font_load_ex("greed_assets/lucida_grande_28px.bft", 0.5f);
		small_font = font_load_ex("greed_assets/lucida_grande_20px.bft", 0.5f);
	}	
	else {
		huge_font = font_load("greed_assets/lucida_grande_30px.bft");
		big_font = font_load("greed_assets/lucida_grande_14px.bft");
		small_font = font_load("greed_assets/lucida_grande_10px.bft");
	}	

	style.texture = gui_tex;
	style.font = big_font;

	style.text_color = COLOR_WHITE;

	style.first_layer = 12;
	style.second_layer = 13;
	style.text_layer = 14;

	style.src_button_up = rectf(0.0f, 0.0f, 252.0f, 41.0f);
	style.src_button_down = rectf(0.0f, 42.0f, 252.0f, 42.0f + 41.0f);
	style.src_switch_off_up = rectf(0.0f, 93.0f, 0.0f + 24.0f, 93.0f + 30.0f);
	style.src_switch_off_down = rectf(23.0f, 93.0f, 23.0f + 24.0f, 93.0f + 30.0f);
	style.src_switch_on_up = rectf(48.0f, 93.0f, 48.0f + 24.0f, 93.0f + 30.0f);
	style.src_switch_on_down = rectf(74.0f, 93.0f, 74.0f + 24.0f, 93.0f + 30.0f);
	style.src_slider = rectf(0.0f, 126.0f, 254.0f, 126.0f + 18.0f);
	style.src_slider_knob_up = rectf(1.0f, 149.0f, 1.0f + 18.0f, 149.0f + 18.0f);
	style.src_slider_knob_down = rectf(20.0f, 149.0f, 20.0f + 18.0f, 149.0f + 18.0f);

	return style;
}
Esempio n. 3
0
void background_init(void) {
	background = tex_load(BACKGROUND_IMG);
	triangle = tex_load(TRIANGLE_IMG);
}
Esempio n. 4
0
void load_glslshaderbind () {

	int		i;
	int		num;
	char	string_name[128];
	char	string_type[128];
	char	string_value[512];
	
	varFloat*					vfloat;
	varVec2*					vec2;
	varVec3*					vec3;
	varVec4*					vec4;
	varSampler2D*				sampler2D;
	script_variable_matrix_4x4*	pVariableMatrix4x4;

	
	// script validation
	// 2 strings needed: Vertex and fragment shader path
	if (mySection->stringNum < 2){
		section_error("At least 2 strings are needed: vertex and fragment shader files");
		return;
	}
	
	local = malloc(sizeof(glslshaderbind_section));
	mySection->vars = (void *) local;
	
	// load program, 2 first strings are vertex and fragment program paths
	local->program = glslshad_load(mySection->strings[0], mySection->strings[1]);
	if (local->program == -1)
		return;
	glslshad_upload(local->program);
	glslshad_bind(local->program);	// We need to use the program (bind it) in order to retrieve it locations (some drivers need it)
	
	// Reset variables
	local->vfloat_num		= 0;
	local->vec2_num			= 0;
	local->vec3_num			= 0;
	local->vec4_num			= 0;
	local->sampler2D_num	= 0;
	local->matrix4x4_num	= 0;
	num = 0;
	
	// Read the variables
	for (i=2; i<mySection->stringNum; i++) {
		sscanf ( mySection->strings[i], "%s %s %s", string_type, string_name, string_value);	// Read one string and store values on temporary strings for frther evaluation
		dkernel_trace("glslshaderbind: string_type [%s], string_name [%s], string_value [%s]", string_type, string_name, string_value);
		remove_spaces(string_value);

		if (strcmp(string_type,"float")==0)	// FLOAT detected
		{
			num = max_shader_reached ( local->vfloat_num++ );
			vfloat = &(local->vfloat[num]);
			strcpy (vfloat->name, string_name);
			strcpy (vfloat->equation, string_value);
			vfloat->loc = glslshad_getUniformLocation (local->program, vfloat->name);
			vfloat->eva.equation = vfloat->equation;
			initExpression(&vfloat->eva);		// Inits the evaluator
		}
		else if (strcmp(string_type,"vec2")==0)	// VEC2 detected
		{
			num = max_shader_reached ( local->vec2_num++ );
			vec2 = &(local->vec2[num]);
			strcpy (vec2->name, string_name);
			strcpy (vec2->equation, string_value);
			vec2->loc = glslshad_getUniformLocation (local->program, vec2->name);
			vec2->eva.equation = vec2->equation;
			initExpression(&vec2->eva);		// Inits the evaluator
		}
		else if (strcmp(string_type,"vec3")==0)	// VEC3 detected
		{
			num = max_shader_reached ( local->vec3_num++ );
			vec3 = &(local->vec3[num]);
			strcpy (vec3->name, string_name);
			strcpy (vec3->equation, string_value);
			vec3->loc = glslshad_getUniformLocation (local->program, vec3->name);
			vec3->eva.equation = vec3->equation;
			initExpression(&vec3->eva);		// Inits the evaluator
		}
		else if (strcmp(string_type,"vec4")==0)	// VEC4 detected
		{
			num = max_shader_reached ( local->vec4_num++ );
			vec4 = &(local->vec4[num]);
			strcpy (vec4->name, string_name);
			strcpy (vec4->equation, string_value);
			vec4->loc = glslshad_getUniformLocation (local->program, vec4->name);
			vec4->eva.equation = vec4->equation;
			initExpression(&vec4->eva);		// Inits the evaluator
		}
		else if (strcmp(string_type,"sampler2D")==0)	// Texture (sampler2D) detected
		{
			num = max_shader_reached ( local->sampler2D_num++ );
			sampler2D = &(local->sampler2D[num]);
			strcpy (sampler2D->name, string_name);
			// If sampler2D is a fbo...
			if (0 == strncmp("fbo",string_value,3))	{
				int fbonum;
				sscanf(string_value, "fbo%d",&fbonum);
				if (fbonum<0 || fbonum>(FBO_BUFFERS - 1)) {
					section_error("sampler2D fbo not correct, it should be 'fboX', where X=>0 and X<=%d, you choose: %s", (FBO_BUFFERS - 1), string_value);
					return;
				}
				else {
					sampler2D->texture = demoSystem.fboRenderingBuffer[fbonum];
					sampler2D->texGLid = fbo_get_texbind_id(sampler2D->texture);
				}
			}
			// Is it s a normal texture...
			else {
				sampler2D->texture = tex_load (string_value, USE_CACHE);
				if (sampler2D->texture == -1)
					return;
				tex_properties(sampler2D->texture, NO_MIPMAP);
				tex_upload (sampler2D->texture, USE_CACHE);
				sampler2D->texGLid = tex_get_OpenGLid(sampler2D->texture);
			}
			sampler2D->loc = glslshad_getUniformLocation (local->program, sampler2D->name);
			glUniform1i(sampler2D->loc, (GLuint)num);
		}
		else if (strcmp(string_type,"mat4")==0)	{
			num = max_shader_reached( local->matrix4x4_num++ );
			pVariableMatrix4x4 = &local->matrix4x4[num];
			strcpy(pVariableMatrix4x4->m_name, string_name);
				
			// remove the ';'
			if (string_value[0] != '\0')
				string_value[strlen(string_value)-1] = '\0';
				
			pVariableMatrix4x4->m_SVEVariableID = get_sve_variable_id(string_value);
			pVariableMatrix4x4->m_ShaderUniformID = glslshad_getUniformLocation(local->program, pVariableMatrix4x4->m_name);
				
			// check whether the requested SVE Matrix4x4 variable exists
			/*
			if (get_sve_variable_type(pVariableMatrix4x4->m_SVEVariableID) != sve_variable_type_matrix_4x4f)
				{
				section_error("\"%s\" is not a valid SVE Engine Matrix4x4 variable", string_value);
				return;
				}
			*/
		}
	}
	
	// Unbind any shader used
	glslshad_reset_bind();
	glUseProgram(0);
	mySection->loaded=1;
}
Esempio n. 5
0
int dgreed_main(int argc, const char** argv) {
	log_init("pview.log", LOG_LEVEL_INFO);
	video_init(800, 600, "PView");
	rand_init(666);

	GuiDesc style = greed_gui_style(false);

	gui_init(&style);
	particles_init("greed_assets/", 5);

	TexHandle empty = tex_load("greed_assets/empty.png");

	if(psystem_descs_count < 1) 
		LOG_ERROR("No particle systems described!");
	
	int active_backg = 0;
	int active_desc = 0;
	const char* active_desc_name = psystem_descs[active_desc].name;

	RectF gui_area = rectf(0.0f, 0.0f, 520.0f, 80.0f);		
	RectF gui_area2 = rectf(0.0f, 500.0f, 280.0f, 600.0f);
	Vector2 button_prev_pos = vec2(10.0f, 10.0f);
	Vector2 button_next_pos = vec2(280.0f, 10.0f);
	Vector2 button_backg_pos = vec2(10.0f, 550.0f);
	Vector2 label_name_pos = vec2(20.0f, 60.0f);
	char label_text[256];
	
	while(system_update()) {
		RectF src = rectf_null();
		RectF dest = {0.0f, 0.0f, EDITOR_WIDTH, EDITOR_HEIGHT};
		Color c = backgrounds[active_backg % ARRAY_SIZE(backgrounds)];
		video_draw_rect(empty, 0, &src, &dest, c);
		if(mouse_down(MBTN_LEFT)) {
			uint x, y;
			mouse_pos(&x, &y);
			Vector2 pos = vec2((float)x, (float)y);
			if(!rectf_contains_point(&gui_area, &pos))
				if(!rectf_contains_point(&gui_area2, &pos))
					particles_spawn(active_desc_name, &pos, 0.0f);
		}	

		particles_update(time_ms() / 1000.0f);

		sprintf(label_text, "Current psystem: %s", active_desc_name);
		gui_label(&label_name_pos, label_text); 	
		if(gui_button(&button_prev_pos, "Previuos")) 
			active_desc = MAX(0, active_desc-1);
		if(gui_button(&button_next_pos, "Next"))
			active_desc = MIN(psystem_descs_count-1, active_desc+1);
		if(gui_button(&button_backg_pos, "Background color"))
				active_backg++;
		active_desc_name = psystem_descs[active_desc].name;	

		particles_draw();
		draw_grid(0, 12.0f);

		video_present();
	}	

	tex_free(empty);
	particles_close();
	gui_close();
	greed_gui_free();
	video_close();
	
	log_close();
	return 0;
}