示例#1
0
文件: main.c 项目: GoranM/wtetris
int main(int argc, char* argv[]){


	display.create(640, 480);


	// Load geometry data
	//
	GLuint bo_vertex, bo_index;
	glGenBuffers(1, &bo_vertex);
	glGenBuffers(1, &bo_index);

	GLuint* count_nodes = rawdimp("../wtetris/scene.rawd", bo_vertex, bo_index);
	Geom* nodes = (Geom*)(count_nodes + 1);
	Geom* goem_border = nodes;
	Geom* geom_digits = nodes + 1;



	// Create and load shader programs
	//
	char* src_vs = file.loadText("../wtetris/shaders/base.vs");
	char* src_fs = file.loadText("../wtetris/shaders/base.fs");

	GLuint vs = gl.createShader(GL_VERTEX_SHADER, src_vs);
	GLuint fs = gl.createShader(GL_FRAGMENT_SHADER, src_fs);

	GLuint program = gl.createProgram(vs, fs);

	glUseProgram(program);



	// Get handle to shader vars
	//
	GLint loc_world = glGetUniformLocation(program, "world");
	GLint loc_view = glGetUniformLocation(program, "view");
	GLint loc_proj = glGetUniformLocation(program, "proj");
	


	// Camera setup - projecton and initial position
	Camera cam;
	cam.loc_view = loc_view;
	cam.loc_proj = loc_proj;
	matIdent(cam.mat_world);
	toggleProjection(&cam);

	float* p = &cam.mat_world[12];
	p[0] = 12; p[1] = 30; p[2] = 40;



	// Hide mouse, and set to center
	mouse.hide();
	mouse.setPos(display.getWidth()/2, display.getHeight()/2);

	// Persistent OpenGL state
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);
	glPolygonMode(GL_FRONT, GL_LINE);

	

	
	// Core struct init
	//
	scene.cam = &cam;
	
	Array objects;
	arrayInit(&objects, 5);
	scene.objects = &objects;
	

	// Visible objects ===================================
	
	Board board;
	boardInit(&board, goem_border, 20, 12);

	arrayAppend(&objects, &board);

	
	Label title;
	labelInit(&title, -12.5, 30, geom_digits);
	char text_title[] = "wtetris";
	labelSet(&title, text_title);
	labelScaleSet(&title, 5);

	arrayAppend(&objects, &title);

	Label info;
	labelInit(&info, -3.5, 20, geom_digits);
	char text_info[] = "start:enter\nquit:q";
	labelSet(&info, text_info);
	labelScaleSet(&info, 2);

	arrayAppend(&objects, &info);

	Label time;
	labelInit(&time, -16.5, -18.0, geom_digits);
	char score_text[] = "time:\n2501";
	labelSet(&time, score_text);
	labelScaleSet(&time, 2);
	
	arrayAppend(&objects, &time);

	Label score;
	labelInit(&score, 26, -18.0, geom_digits);
	char text[] = "score:\n0000";
	labelSet(&score, text);
	labelScaleSet(&score, 2);

	arrayAppend(&objects, &score);

	// ===================================================


	Wave wave;
	wave.amp = 2;
	wave.wlen = 2;
	wave.time = 1000;
	waveLocsSet(&wave, program);
	wavePosSet(&wave, &board.piece);

	scene.wave = &wave;


	Renderer renderer;
	renderer.loc_world = loc_world;

	// Initial game state
	//
	scene.state = st_title;

	
	// LOOP -----------------------------------------------------------------------
	
	while (1){

		events.process();

		if (keyboard.keyHit('q')){
			break;
		}

		if (keyboard.keyHit('r')){
			toggleProjection(&cam);
		}

		//fpscont(&cam);
		scene.state(&board);
		
		wave.time += 0.2;
		waveToProg(&wave);

		cameraWorldToView(&cam);
		glUniformMatrix4fv(loc_view, 1, 0, cam.mat_view);

		render(&renderer, &scene);

		display.update();


		SDL_Delay(16);
	}

	return 0;

}
示例#2
0
文件: guiUpDownBox.c 项目: ADTL/AFGUI
void defaultUpDownBoxInit(GUI_UPDOWN_BOX * udBox, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
	//unsigned int textWidth;
	uint16_t temp, yd;

	udBox->wmObj.xPos 			= x;
	udBox->wmObj.yPos 			= y;
	udBox->wmObj.Width 			= width;
	udBox->wmObj.Height 		= height;


	udBox->wmObj.Color 			= LCD_COLOR_GREYL;

	udBox->wmObj.BorderColor 	= LCD_COLOR_GREYL;
	udBox->wmObj.BorderWidth	= 1;

	udBox->wmObj.Visible 		= 0;
	udBox->wmObj.Enable 		= 0;
	udBox->CycleUpDown			= 1;

	if (udBox->wmLblHead.wmTxt.vFont == 0 || udBox->wmLblEdit.wmTxt.vFont == 0)
	{
		udBox->wmLblHead.wmTxt.vFont = &GL_ArialNarrow_15;
		udBox->wmLblEdit.wmTxt.vFont = &GL_ArialNarrow_15;
	}

	// upDownButtonInit
	temp = (height - udBox->wmLblHead.wmTxt.vFont->Height - 1)/2;
	yd = y + udBox->wmLblHead.wmTxt.vFont->Height;
	defaultTextButtonInit(&udBox->btnUp, x+width-temp, yd, temp, temp);
	defaultTextButtonInit(&udBox->btnDown, x+width-temp, yd+temp, temp, temp);
	if (udBox->btnUp.wmObj.Height - 2*udBox->btnUp.wmObj.BorderWidth > 14)
	{
		ButtonTextInit(&udBox->btnUp, "^", &GL_ArialNarrow_15, ROTATE_0, FLIP_NO, H_ALIGN_CENTER, V_ALIGN_CENTER);
		ButtonTextInit(&udBox->btnDown, "v", &GL_ArialNarrow_15, ROTATE_0, FLIP_NO, H_ALIGN_CENTER, V_ALIGN_CENTER);
	}
	else
	{
		ButtonTextInit(&udBox->btnUp, "^", &GL_Arial_12, ROTATE_0, FLIP_NO, H_ALIGN_CENTER, V_ALIGN_CENTER);
		ButtonTextInit(&udBox->btnDown, "v", &GL_Arial_12, ROTATE_0, FLIP_NO, H_ALIGN_CENTER, V_ALIGN_CENTER);
	}

	// labels position
	labelInit(&udBox->wmLblHead, x, y, width, udBox->wmLblHead.wmTxt.vFont->Height);
	udBox->wmLblHead.wmObj.BorderWidth = 0;
	udBox->wmLblHead.wmObj.Color = LCD_COLOR_GREYL;
	udBox->wmLblHead.wmObj.Visual3D = 0;

	labelInit(&udBox->wmLblEdit, x, yd, width-temp-1, height-(yd-y)-1);
	udBox->wmLblEdit.wmObj.BorderWidth = 2;
	udBox->wmLblEdit.wmObj.Color = LCD_COLOR_WHITE;
	udBox->wmLblEdit.wmObj.Visual3D = 1;
	udBox->wmLblEdit.wmObj.Transparent = 0;

	udBox->btnUp.wmObj.Enable = 1;
	udBox->btnUp.wmObj.Visible = 1;
	udBox->btnDown.wmObj.Enable = 1;
	udBox->btnDown.wmObj.Visible = 1;
	udBox->wmLblHead.wmObj.Enable = 1;
	udBox->wmLblHead.wmObj.Visible = 1;
	udBox->wmLblEdit.wmObj.Enable = 1;
	udBox->wmLblEdit.wmObj.Visible = 1;

	// default Values init
	udBox->Value = 0;
	udBox->ValueMax = 100;
	udBox->ValueMin = 0;
	udBox->ValueInc = 1;
	udBox->ValueFastInc = 5;

	wmTouchInit(&udBox->btnUp.wmTouch);
	wmTouchInit(&udBox->btnDown.wmTouch);
};