Exemplo n.º 1
0
// Main display loop
void display () 
{
	PERF_PUSH ( "frame" );		// instrument code (does CPU and GPU perf)
	
	glClearColor( 0.5, 0.5, 0.5, 1.0 );
	glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

	// Draw 2D funcs similar to immediate mode, but uses VBO buffers internally
	// Draw order maintained. Transparency allowed.
	// start2D() does dynamic redraw every frame. 
	// static2D() will redraw automatically, can be infrequently updated.
	// Commands:
	//    start2D, static2D, end2D, setview2D
	//    drawLine, drawRect, drawFill, drawText, setText
	//    drawCircle, drawCircleFill, drawCircleDash
	// Future goals (partially implemented):
	//    - Ability to change model/view matrix per start2D/end2D sets
	//    - Add/remove static2D sets

	start2D();			
	int x1, y1, x2, y2;
	float r, g, b;
	for (int n=0; n < numRects; n++ ) {
		x1 = n % 40; y1 = n / 40;
		drawFill ( x1*30+30-14, y1*30+200-14, x1*30+30+14, y1*30+200+14, 0, float(y1)/40.0, float(x1)/40.0, 1 );		
	}
	for (int n=0; n < numCircles; n++ ) {
		x1 = n % 40; y1 = n / 40;
		drawCircleFill ( x1*30+30, y1*30+200, 14, float(x1)/40.0, float(y1)/40.0, 1, 1 );
		drawCircleDash ( x1*30+30, y1*30+200, 14, 1, 1, 1, 1 );
	}
	srand ( 3142 );
	for (int n=0; n < numLines; n++ ) {
		x1 = (rand()*window_width)/RAND_MAX;	y1 = (rand()*window_height)/RAND_MAX;
		x2 = (rand()*window_width)/RAND_MAX;	y2 = (rand()*window_height)/RAND_MAX;
		r = float(rand())/RAND_MAX; g = float(rand())/RAND_MAX; b = float(rand())/RAND_MAX; 
		drawLine ( x1, y1+200, x2, y2+200, r, g, b, 1 );
	}
	end2D ();

	// multiple start/end blocks allowed per frame	
	start2D ();	
	char msg[128];
	for (int n=0; n < numText; n++ ) {		
		x1 = n % 40; y1 = n / 40;
		sprintf ( msg, "%d,%d", x1, y1 );
		drawText ( x1*30+30-12, y1*30+200, msg, 1, 1, 1, 1);
	}
	end2D();

	// DrawGui - required to draw GUI
	drawGui ();	

	// Draw2D - required to draw nv2D
	draw2D ();

	frameTime = PERF_POP ();  // frame

	SwapBuffers( g_hDC );  		
}
Exemplo n.º 2
0
void drawOverlay ()
{
	Vector4DF clr;

	Matrix4F proj, view, model;
	proj.Scale ( 2.0/window_width, -2.0/window_height, 1 );		
	model.Translate ( cam.getToPos().x, cam.getToPos().y, 1 );
	view.Scale ( cam.getToPos().z, 1, 1 );
	view *= model;
	model.Identity ();

	//----- 2D Drawing (visualizer space)	
	setview2D ( model.GetDataF(), view.GetDataF(), proj.GetDataF() );
	setorder2D ( false, 1 );
	updatestatic2D ( 0 );		// update model/view/proj matrices of each static draw layer
	updatestatic2D ( 1 );
	updatestatic2D ( 2 );
	updatestatic2D ( 3 );
		
	// Selector Bar
	start2D ();					
	  drawRect ( mSelectID*10, 0, mSelectID*10+10, NUM_BIN*25, 1,1,1,1 );

	// Same-State Highlights (yellow)
	int minE = (((0-window_width/2.0)/cam.getToPos().z) - cam.getToPos().x) / 10;
	int maxE = (((window_width - window_width/2.0)/cam.getToPos().z) - cam.getToPos().x) / 10;
	minE = ( minE < 0 ) ? 0 : minE;
	maxE = ( maxE >= mEvents.size() ) ? mEvents.size() : maxE;
	for (int n=0; n < mEvents.size(); n++ ) {
		if ( mEvents[n].bin_id[mSelectBin] == mEvents[mSelectID].bin_id[mSelectBin] && n > minE && n < maxE ) {
			drawRect ( n*10, mSelectBin*25, n*10+10, mSelectBin*25+24, 1,1,0,1 );
			drawRect ( n*10+1, mSelectBin*25+1, n*10+9, mSelectBin*25+23, 1,1,0,1 );
		}
	}
	end2D ();
	
	//----- 2D Drawing (screen space)	
	setview2D ( window_width, window_height );	// change to screen space
	setorder2D ( true, -0.00001 );
	
	start2D ();					// dynamic draw
	int panel_width = 200;
	float xoff = window_width - panel_width;
	float yoff = cam.getToPos().y + (window_height/2);

	// Left panel - Bin Text 
	char name[128];
	char msg[1024];

	int frame = mEvents[mSelectID].frame; 
	frame = (frame < 0 || frame >= mFrames.size() ) ? 0 : frame;
	Frame& f = mFrames[ frame ];

	drawFill ( 0, yoff, +panel_width, yoff + NUM_BIN*25+250, 0.15,0.15,0.2,0.75 );
	
	drawText ( 10, yoff-85, "Frame #:", 1,1,1,1 );
	drawText ( 10, yoff-70, "Frame Draws:", 1,1,1,1 );
	drawText ( 10, yoff-55, "Frame Prims:", 1,1,1,1 );
	drawText ( 10, yoff-40, "Frame Transfer:", 1,1,1,1 );	
	drawText ( 10, yoff-20, "Frame States:", 1,1,1,1 );	
	sprintf ( msg, "%d", frame );					drawText ( 100, yoff - 85, msg, 1,1,1,1 );	
	sprintf ( msg, "%d", f.totalDraw );				drawText ( 100, yoff - 70, msg, 1,1,1,1 );
	sprintf ( msg, "%d", f.totalPrim );				drawText ( 100, yoff - 55, msg, 1,1,1,1 );
	sprintf ( msg, "%d bytes", f.totalTransfer );	drawText ( 100, yoff - 40, msg, 1,1,1,1 );

	setText ( 0.8, 0 );
	drawText ( 100, yoff - 20, "Modify", 1,0,0,1 );
	drawText ( 125, yoff - 10, "Switch", 1,0.5,0,1 );
	drawText ( 150, yoff - 20, "Reuse", 0,1,0,1 );
	drawText ( 175, yoff - 10, "Unique", 1,1,1,1 );
	drawTri ( 100, yoff-10, 100+10, yoff-10, 100, yoff, 1, 0,0, 1);
	drawTri ( 125, yoff-10, 125+10, yoff-10, 125, yoff, 1,.5,0, 1);
	drawTri ( 150, yoff-10, 150+10, yoff-10, 150, yoff, 0, 1,0, 1);
	setText ( 1.0, -0.5 );

	for (int b=0; b < NUM_BIN; b++ ) {
		strncpy ( name, binNames[b].c_str(), 128 );
		drawText ( 8, yoff + b*25+12, name, 1,1,1,1 );

		clr.x = float(f.binChange[b]) / f.totalDraw;	if ( clr.x > 1 ) clr.x = 1;
		sprintf ( msg, "%d", f.binChange[b] );	drawText ( 100, yoff + b*25+12-2, msg, clr.x*0.7+0.3, 0,0,1 );	
		
		clr.x = float(f.binSwitch[b]) / f.totalDraw;	if ( clr.x > 1 ) clr.x= 1;
		sprintf ( msg, "%d", f.binSwitch[b] );	drawText ( 125, yoff + b*25+12+2, msg, clr.x*0.7+0.3,clr.x*.4+0.2,0,1 );
		
		clr.x = float(f.binReuse[b]) / f.totalDraw; 	if ( clr.x > 1 ) clr.x= 1;
		sprintf ( msg, "%d", f.binReuse[b] );	drawText ( 150, yoff + b*25+12-2, msg, 0, clr.x*0.7+0.3, 0,1 );

		sprintf ( msg, "%d", f.binUnique[b] );	drawText ( 175, yoff + b*25+12+2, msg, .7, .7, .7,1 );
	}

	int ys = NUM_BIN*25;
	float ypos; 
	sprintf ( msg, "%d", mMaxPrim/4 ); 
	drawLine ( 0, yoff + ys+25, 200, yoff+ys+25, .6, .6, .6, 1);	
	drawText ( 10, yoff+ys+25+15, msg, .8,.8,.8,1 );
	drawText ( 10, yoff + ys+80, "# Prims", 1, 1, 1, 1 );
	drawText ( 10, yoff+ys+125, "0", .8,.8,.8,1 );
	drawLine ( 0, yoff + ys+125, 200, yoff+ys+125, .6, .6, .6, 1);
	ypos = mEvents[ mSelectID ].bin_id[ BIN_DRAW ] * 400 / mMaxPrim;		// prim count	
	clr = getClr ( mEvents[ mSelectID ].bin_id[9] + 9*16384 );
	if ( ypos > 100 ) ypos = 100;			
	sprintf ( msg, "%d", mEvents[ mSelectID ].bin_id[BIN_DRAW] );
	drawLine ( 150, yoff+ys+(125-ypos), 200, yoff+ys+(125-ypos), clr.x,clr.y,clr.z,1 );
	drawText ( 150, yoff+ys+(125-ypos), msg, clr.x,clr.y,clr.z,1 );

	sprintf ( msg, "%d", mMaxSize ); 
	drawLine ( 0, yoff + ys+150, 200, yoff+ys+150, .6, .6, .6, 1);
	drawText ( 10, yoff+ys+150+15, msg, .8,.8,.8,1 );
	drawText ( 10, yoff + ys+200, "Transfer (bytes)" , 1, 1, 1, 1);
	drawText ( 10, yoff+ys+250, "0", .8,.8,.8,1 );
	drawLine ( 0, yoff + ys+250, 200, yoff+ys+250, .6, .6, .6, 1);
	ypos = mEvents[ mSelectID ].bin_size [ BIN_SIZE ] * 100 / mMaxSize;		// prim count
	if ( ypos > 100 ) ypos = 100;	
	sprintf ( msg, "%d", mEvents[ mSelectID ].bin_size [BIN_SIZE] );
	drawLine ( 150, yoff+ys+(250-ypos), 200, yoff+ys+(250-ypos), 1,1,1,1 );
	drawText ( 150, yoff+ys+(250-ypos), msg, 1,1,1,1 );
		
	// Right panel - Call Text		
	drawFill ( xoff, yoff, xoff + panel_width, yoff + NUM_BIN*25+250, 0.15,0.15,0.2,0.75 );	
	int cid;
	glColor3f ( 1, 1, 1);
	
	for (int c = 0; c < mEvents[ mSelectID ].call_num; c++ ) {	
		cid = mEvents[ mSelectID ].call_start + c;		
		clr = getClr ( mCalls[cid].val_id + mCalls[cid].bin_id*16384 );
		clr.w = 1;
		drawFill ( xoff+100, yoff + c*15, xoff+125, yoff+c*15+13, clr.x, clr.y, clr.z, clr.w );

		sprintf ( msg, "%s", mCalls[cid].name.c_str() );  
		drawText ( xoff+5, yoff + c*15+15, msg, 1,1,1,1 );

		sprintf ( msg, "%02d  %d %d", mCalls[cid].bin_id, mCalls[cid].size, mCalls[cid].val_id );
		drawText ( xoff+130, yoff + c*15+15, msg, 1,1,1,1 );
	}
	end2D ();
	
	

	#ifdef USE_DX
		g_pContext->OMSetDepthStencilState( g_pDepthStencilState, 1 );
	#endif
}
Exemplo n.º 3
0
void GraphicEngine::renderWorld()
{
	glMatrixMode(GL_MODELVIEW); // set modelview matrix
	glLoadIdentity(); // clear the current matrix

	// Offsets
	glTranslatef(masterPositionOffset.x, masterPositionOffset.y, masterPositionOffset.z);
	glRotatef(masterOrientationOffset.x, 1.0f, 0.0f, 0.0f);
	glRotatef(masterOrientationOffset.y, 0.0f, 1.0f, 0.0f);
	glRotatef(masterOrientationOffset.z, 0.0f, 0.0f, 1.0f);

	gluLookAt(game->camera->position.x, game->camera->position.y, game->camera->position.z,
			game->camera->lookAt.x + game->camera->position.x, game->camera->lookAt.y + game->camera->position.y, game->camera->lookAt.z + game->camera->position.z,
					game->camera->up.x, game->camera->up.y, game->camera->up.z);
	writeDebugText("Camera position: %0.0f  %0.0f  %0.0f ", game->camera->position.x, game->camera->position.y, game->camera->position.z);
	//writeDebugText("Camera look: %0.2f  %0.2f  %0.2f ", game->camera->lookAt.x, game->camera->lookAt.y, game->camera->lookAt.z);


	static vector<GameObject*> objects_for_drawing;
	static vector<GOLight*> lights;
	static vector<GameObject*> opaque_objects;
	static vector<GameObject*> transparent_objects;
	static vector<GameObject*> _2d_objects;
	objects_for_drawing.clear();
	lights.clear();
	opaque_objects.clear();
	transparent_objects.clear();
	_2d_objects.clear();

	for (unsigned int i = 0; i < game->objects.size(); i++ ) {
		if (game->objects.at(i)->getNeedDraw()) {
			objects_for_drawing.push_back(game->objects.at(i));
		}
	}

	if (Game::instance->drawBBoxes) {
		if (renderFilter) {
			renderFilter->debugDraw();
			for (unsigned int i = 0; i < objects_for_drawing.size(); i++ ) {
				GameObject* o = objects_for_drawing.at(i);
				renderFilter->debugObjectDraw(o);
			}
		} else {
			for (unsigned int i = 0; i < objects_for_drawing.size(); i++ ) {
				drawBBox(objects_for_drawing.at(i)->getBBox());
			}
		}
	}

	for (unsigned int i = 0; i < objects_for_drawing.size(); i++ ) {
		if (objects_for_drawing.at(i)->type == GO_LIGHT) {
			lights.push_back((GOLight*)objects_for_drawing.at(i));
		} else
		if (objects_for_drawing.at(i)->is2D) {
			_2d_objects.push_back(objects_for_drawing.at(i));
		} else
		if (objects_for_drawing.at(i)->opaque) {
			opaque_objects.push_back(objects_for_drawing.at(i));
		} else {
			transparent_objects.push_back(objects_for_drawing.at(i));
		}
	}

	if (renderFilter && !Game::instance->editorMode) {
		opaque_objects = renderFilter->doFilter(opaque_objects);
		transparent_objects = renderFilter->doFilter(transparent_objects);
	}
	game->drawnObjectsCount = opaque_objects.size();
	game->drawnObjectsCount += transparent_objects.size();
	game->drawnObjectsCount += _2d_objects.size();

	sort(transparent_objects.begin(), transparent_objects.end(), sortTransparent);

	for (unsigned int i = 0; i < lights.size(); i++ ) {
		lights.at(i)->draw();
	}

	for (unsigned int i = 0; i < opaque_objects.size(); i++ ) {
		opaque_objects.at(i)->draw();
		//writeDebugText("Type: %i, id: %s, z:%f", opaque_objects.at(i)->type, opaque_objects.at(i)->id.c_str(), opaque_objects.at(i)->position.z);
	}

	game->transparentObjectsCount = transparent_objects.size();
	for (unsigned int i = 0; i < transparent_objects.size(); i++ ) {
		transparent_objects.at(i)->draw();
		//writeDebugText("Type: %i, id: %s, z:%f", transparent_objects.at(i)->type, transparent_objects.at(i)->id.c_str(), (transparent_objects.at(i)->position - game->camera->position).Length());
	}

	if (game->debugPhysDraw) {
		if (game->debugPhysDrawIn2D)
			start2D();
			game->dynamicsWorld->debugDrawWorld();
		if (game->debugPhysDrawIn2D)
			end2D();
	}

	// Ligt reset
	for (unsigned int i = 0; i < lights.size(); i++ ) {
		lights.at(i)->cancel();
	}

#ifndef OPENGL_ES
	// for drawibg texts
	glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
#endif
	// save previous state of lighting
	bool lightingEnabled = glIsEnabled(GL_LIGHTING);
	glDisable(GL_LIGHTING);

	// Write 2D stuff
	start2D();

	// sort Z
	sort(_2d_objects.begin(), _2d_objects.end(), sort2D);

	game->_2dObjectsCount = _2d_objects.size();
	for (unsigned int i = 0; i < _2d_objects.size(); i++ ) {
		_2d_objects.at(i)->draw();
		//writeDebugText("Type: %i, id: %s, z:%f", opaque_objects.at(i)->type, opaque_objects.at(i)->id.c_str(), opaque_objects.at(i)->position.z);
	}

	// Draw debug texts
	for (unsigned int i = 0; i < debugStrings.size(); i++ ) {
		if (game->drawDebugText && !game->console->isOpened()) {
			std::pair <float, float>* size = new std::pair <float, float>();
			standart14Normal->GetStringSize(debugStrings.at(i).c_str(), size);

			static GOPlate* p = new GOPlate();
			p->setPositioningMode(GOPositioningModeTopLeft);
			p->color = MGColor(0.0f,0.0f,0.0f,0.4f);

			int h = (int)(size->second * 1.00);
			p->setSize(CVector(size->first, h));
			p->setPosition(CVector(5.0f, game->osAdapter->getScreenHeight() - (h * i)));
			p->draw();
			writeText(debugStrings.at(i), CVector(5.0f, game->osAdapter->getScreenHeight() - (h * i), 0.0f), STANDART_14_NORMAL, MGColor(0.0f, 1.0f, 0.0f, 1.0f));
		}
	}
	debugStrings.clear();

	game->luaVM->doString("_onDraw2D()");
	end2D();

	if (lightingEnabled) {
		glEnable(GL_LIGHTING);
	} else {
		glDisable(GL_LIGHTING);
	}

}