Example #1
0
void widget_text_draw(widget *w)
{
	if(!w)return;
	float dx = 0.0f;
	glColor4f(1,1,1,1);
	sth_begin_draw(stash);
	sth_draw_text(stash, w->fontface, w->fontsize, 10, 10, w->data, &dx);
	sth_end_draw(stash);
//	sth_vmetrics(stash, 1,24, NULL,NULL,&height);
}
Example #2
0
void widget_button_draw(widget *w)
{
	float colour = 0.0f;
	if(w->clicked)colour = 0.3f;
	glColor4f(colour, colour, colour, 0.4f);
	draw_rect(w->size.x, w->size.y);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	sth_begin_draw(stash);
	sth_draw_text(stash, w->fontface, w->fontsize,
			10, -(w->size.y/2+5), w->data, 0);
	sth_end_draw(stash);
}
Example #3
0
void ofxFontStash::drawBatch( string text, float size, float x, float y){
	if (stash != NULL){
		if(batchDrawing){
			float dx = 0;
			sth_begin_draw(stash);
			sth_draw_text( stash, stashFontID, size, x, y, text.c_str(), &dx ); //this might draw
			sth_end_draw(stash); // this actually draws
		}else{
			ofLogError("ofxFontStash", "can't drawBatch() without calling beginBatch() first!");
		}
	}else{
		ofLogError("ofxFontStash", "can't drawBatch() without having been setup first!");
	}
}
Example #4
0
void ofxFontStash::draw( string text, float size, float x, float y){
	
	if (stash != NULL){
		float dx = 0;
		
		glPushMatrix();
		glTranslatef(x, y, 0.0);
		sth_begin_draw(stash);
		sth_draw_text( stash, stashFontID, size, 0, 0 , text.c_str(), &dx ); //this might draw
		sth_end_draw(stash); // this actually draws
		glPopMatrix();
	}else{
		ofLogError("ofxFontStash", "can't draw() without having been setup first!");
	}		
}
Example #5
0
void widget_menu_draw(widget *w)
{
	float colour = 0.0f;
	if(w->clicked)colour = 0.3f;
	if(mouse_x > w->parent->pos.x)
	if(mouse_x < w->parent->pos.x + w->parent->size.x)
	if(mouse_y > w->parent->pos.y + w->pos.y)
	if(mouse_y < w->parent->pos.y + w->pos.y + w->size.y)
	{	// hovering
		if(!w->noClick)colour = 0.1;
	}
	glColor4f(colour, colour, colour, 0.4f);
	draw_rect(w->parent->size.x, w->size.y);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	sth_begin_draw(stash);
	sth_draw_text(stash, w->fontface, w->fontsize,
			10, -(w->size.y/2+5), w->data, 0);
	sth_end_draw(stash);
}
Example #6
0
void gui_draw(void)
{
	widget_draw(widget_root);

	long long delta_time, this_time = sys_time();
	delta_time = this_time - last_time;
	last_time = this_time;
//	double DeltaTime = (double)delta_time / (double)sys_ticksecond;

	frame_number++;
	if(frame_number>=MAX_FRAMES) frame_number=0;
	frame_time[frame_number] = (long)delta_time;
	long fps_sum = 0;
	for(int i=0; i<MAX_FRAMES; i++)
		fps_sum += frame_time[i];

	double fps = (double)MAX_FRAMES / ((double)fps_sum / (double)sys_ticksecond);

	glColor4f(1,1,1,1);
	sth_begin_draw(stash);
	char tempstr[50];
	sprintf(tempstr, "%4.1fHz", fps);
	sth_draw_text(stash, 3, 30, vid_width-90, -26, tempstr, 0);
#ifndef __APPLE__
	int i;
	for(i=0; i< nvml_device_count; i++)
	{
		sprintf(tempstr, "%d°C", nvml_gputemp[i]);
		sth_draw_text(stash, 3, 30, vid_width-70, -(50+i*50), tempstr, 0);
	}
	for(int j=0; j< adl_device_count; j++)
	{
		sprintf(tempstr, "%d°C", adl_gputemp[j]);
		sth_draw_text(stash, 3, 30, vid_width-70, -(50+(i+j)*50), tempstr, 0);
	}
#endif
	sth_end_draw(stash);

	gui_http_draw();


}
Example #7
0
void widget_window_ocl_draw(widget *w)
{
	widget_window_draw(w);
	float left=10, right=w->size.x - 10;
	float top=-40, bottom = -w->size.y + 10;

	glColor4f(1,1,1,1);
	sth_begin_draw(stash);
	sth_draw_text(stash, 3, 20.0f, 6, -20, "\u2211", 0);
	sth_end_draw(stash);

	if(w->clicked == 10)
	{
		glColor4f(0.5f, 0.5f, 0.2f, 0.4f);
		glTranslatef(0, -5, 0);
		draw_rect(20, 23);
		glTranslatef(0, 5, 0);
		glColor4f(1,1,1,1);
	}


	float tx = (float)(w->size.x-20)/(float)sys_width;
	float ty = (float)(w->size.y-50)/(float)sys_height;

	OCLPROGRAM *p = w->data2;

	glColor4f(1,1,1,1);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, p->GLid[0]);
	glBegin(GL_QUADS);
	glTexCoord2f(0, 0); glVertex2f(left, top);
	glTexCoord2f(tx, 0); glVertex2f(right, top);
	glTexCoord2f(tx, ty); glVertex2f(right, bottom);
	glTexCoord2f(0, ty); glVertex2f(left, bottom);
	glEnd();
	glBindTexture(GL_TEXTURE_2D, 0);
	glDisable(GL_TEXTURE_2D);
}
Example #8
0
void ofxFontStash::drawMultiLine( string text, float size, float x, float y){
	
	if (stash != NULL){

		glPushMatrix();
			glTranslatef(x, y, 0.0f);
			sth_begin_draw(stash);
			
			stringstream ss(text);
			string s;
			int line = 0;
			while ( getline(ss, s, '\n') ) {
				//cout << s << endl;
				float dx = 0;
				sth_draw_text( stash, stashFontID, size, 0.0f, size * lineHeight * OFX_FONT_STASH_LINE_HEIGHT_MULT * line, s.c_str(), &dx );
				line ++;
			}
			sth_end_draw(stash);
		glPopMatrix();

	}else{
		ofLogError("ofxFontStash", "can't drawMultiLine() without having been setup first!");
	}		
}
Example #9
0
int main(int argc, char *argv[]) {
	int done;
	SDL_Event event;
	int width, height;
	struct sth_stash* stash = 0;
	FILE* fp = 0;
	int datasize;
	unsigned char* data;
	float sx,sy,dx,dy,lh;
	int droidRegular, droidItalic, droidBold, droidJapanese, dejavu;
	SDL_Surface* surface;
	GLuint texture;

	if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
	{
		fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
		return -1;
	}


	// Init OpenGL
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
    SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

#ifdef STH_OPENGL3
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
#endif



	width = 800;
	height = 600;	

    SDL_Window* window = SDL_CreateWindow("FontStash Demo", 100, 100, width, height, SDL_WINDOW_OPENGL);

	if (!window)
	{
		fprintf(stderr, "Could not initialise SDL opengl\n");
		return -1;
	}

    SDL_GLContext context = SDL_GL_CreateContext(window);
	
	stash = sth_create(512,512);
	if (!stash)
	{
		fprintf(stderr, "Could not create stash.\n");
		return -1;
	}

	// Load the first truetype font from memory (just because we can).
	fp = fopen("DroidSerif-Regular.ttf", "rb");
	if (!fp) goto error_add_font;
	fseek(fp, 0, SEEK_END);
	datasize = (int)ftell(fp);
	fseek(fp, 0, SEEK_SET);
	data = (unsigned char*)malloc(datasize);
	if (data == NULL) goto error_add_font;
	fread(data, 1, datasize, fp);
	fclose(fp);
	fp = 0;
	
	if (!(droidRegular = sth_add_font_from_memory(stash, data)))
		goto error_add_font;

	// Load the remaining truetype fonts directly.
	if (!(droidItalic = sth_add_font(stash,"DroidSerif-Italic.ttf")))
		goto error_add_font;
	if (!(droidBold = sth_add_font(stash,"DroidSerif-Bold.ttf")))
		goto error_add_font;
	if (!(droidJapanese = sth_add_font(stash,"DroidSansJapanese.ttf")))
		goto error_add_font;

	// Load a bitmap font
	surface = IMG_Load("dejavu-sans_0.png");
	if (surface == NULL)
	{
		fprintf(stderr, "%s.\n", IMG_GetError());
		return -1;
	}
	glGenTextures(1, &texture);
	glBindTexture(GL_TEXTURE_2D, texture);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	if (SDL_MUSTLOCK(surface)) SDL_LockSurface(surface);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, surface->w, surface->h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, surface->pixels);
	if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface);
	SDL_FreeSurface(surface);
	dejavu = sth_add_bitmap_font(stash, 17, -4, 2);
	sth_add_glyph_for_char(stash, dejavu, texture, "T", 18, 14, 363, 331, 10, 11, 0,  3, 10);
	sth_add_glyph_for_char(stash, dejavu, texture, "h", 18, 14, 225, 382,  8, 11, 1,  3, 10);
	sth_add_glyph_for_char(stash, dejavu, texture, "i", 18, 14, 478, 377,  2, 11, 1,  3,  4);
	sth_add_glyph_for_char(stash, dejavu, texture, "s", 18, 14, 199, 455,  7,  8, 1,  6,  9);
	sth_add_glyph_for_char(stash, dejavu, texture, " ", 18, 14,  66, 185,  1,  1, 0, 14,  5);
	sth_add_glyph_for_char(stash, dejavu, texture, "a", 18, 14,  18, 459,  8,  8, 1,  6, 10);
	sth_add_glyph_for_char(stash, dejavu, texture, "b", 18, 14, 198, 383,  8, 11, 1,  3, 10);
	sth_add_glyph_for_char(stash, dejavu, texture, "t", 18, 14, 436, 377,  5, 11, 1,  3,  6);
	sth_add_glyph_for_char(stash, dejavu, texture, "m", 18, 14, 494, 429, 12,  8, 2,  6, 16);
	sth_add_glyph_for_char(stash, dejavu, texture, "p", 18, 14, 436, 353,  8, 11, 1,  6, 10);
	sth_add_glyph_for_char(stash, dejavu, texture, "f", 18, 14, 442, 377,  5, 11, 1,  3,  7);
	sth_add_glyph_for_char(stash, dejavu, texture, "o", 18, 14, 483, 438,  8,  8, 1,  6, 10);
	sth_add_glyph_for_char(stash, dejavu, texture, "n", 18, 14,   0, 459,  8,  8, 1,  6, 10);
	sth_add_glyph_for_char(stash, dejavu, texture, ".", 18, 14, 285, 476,  2,  3, 1, 11,  6);
	
	done = 0;
	while (!done)
	{
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_MOUSEMOTION:
					break;
				case SDL_MOUSEBUTTONDOWN:
					break;
				case SDL_KEYDOWN:
					if (event.key.keysym.sym == SDLK_ESCAPE)
						done = 1;
					break;
				case SDL_QUIT:
					done = 1;
					break;
				default:
					break;
			}
		}
		
		// Update and render
		glViewport(0, 0, width, height);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glClearColor(0.3f, 0.3f, 0.32f, 1.0f);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

#ifdef STH_OPENGL3
        std::cout << "OpenGL3" << std::endl;
        glm::mat4 proj = glm::ortho(0.0f, (GLfloat) width, 0.0f, (GLfloat) height, -1.0f, 1.0f);

        sth_projection_matrix(stash, glm::value_ptr(proj));
        sth_color(stash, 1.0f, 0.0f, 0.0f, 1.0f);
#else
        std::cout << "Immediate OpenGL" << std::endl;
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0,width,0,height,-1,1);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();

		glColor4ub(255,255,255,255);
#endif

		sx = 100; sy = 250;
		
		sth_begin_draw(stash);
		
		dx = sx; dy = sy;
		sth_draw_text(stash, droidRegular, 24.0f, dx, dy, "The quick ", &dx);
		sth_draw_text(stash, droidItalic, 48.0f, dx, dy, "brown ", &dx);
		sth_draw_text(stash, droidRegular, 24.0f, dx, dy, "fox ", &dx);
		sth_vmetrics(stash, droidItalic, 24, NULL, NULL, &lh);
		dx = sx;
		dy -= lh*1.2f;
		sth_draw_text(stash, droidItalic, 24.0f, dx, dy, "jumps over ", &dx);
		sth_draw_text(stash, droidBold, 24.0f, dx, dy, "the lazy ", &dx);
		sth_draw_text(stash, droidRegular, 24.0f, dx, dy, "dog.", &dx);
		dx = sx;
		dy -= lh*1.2f;
		sth_draw_text(stash, droidRegular, 12.0f, dx, dy, "Now is the time for all good men to come to the aid of the party.", &dx);
		sth_vmetrics(stash, droidItalic, 12, NULL, NULL, &lh);
		dx = sx;
		dy -= lh*1.2f*2;
		sth_draw_text(stash, droidItalic, 18.0f, dx, dy, "Ég get etið gler án þess að meiða mig.", &dx);
		sth_vmetrics(stash, droidItalic, 18, NULL, NULL, &lh);
		dx = sx;
		dy -= lh*1.2f;
		sth_draw_text(stash, droidJapanese, 18.0f, dx, dy, "私はガラスを食べられます。それは私を傷つけません。", &dx);
		dx = sx;
		dy -= lh*1.2f*2;
		sth_draw_text(stash, dejavu, 18.0f, dx, dy, "This is a bitmap font.", &dx);

		sth_end_draw(stash);
		
        SDL_GL_SwapWindow(window);
	}
	
	sth_delete(stash);
	free(data);
    SDL_GL_DeleteContext(context);
	SDL_Quit();
	return 0;

error_add_font:
	fprintf(stderr, "Could not add font.\n");
	return -1;
}
Example #10
0
void ofxFontStash::beginBatch(){
	if(stash != NULL){
		batchDrawing = TRUE;
		sth_begin_draw(stash);
	}
}
Example #11
0
		void UnicodeFont::BeginText()
		{
			sth_begin_draw(_stash);
		}
Example #12
0
int main(int argc, char* argv[])
{
	b3SetCustomPrintfFunc(myprintf);
	b3Vector3 test(1,2,3);
	test.x = 1;
	test.y = 4;

    printf("main start");

	b3CommandLineArgs args(argc,argv);
	ParticleDemo::ConstructionInfo ci;

	if (args.CheckCmdLineFlag("help"))
	{
		Usage();
		return 0;
	}


	args.GetCmdLineArgument("selected_demo",selectedDemo);


	if (args.CheckCmdLineFlag("new_batching"))
	{
		useNewBatchingKernel = true;
	}
	bool benchmark=args.CheckCmdLineFlag("benchmark");
	dump_timings=args.CheckCmdLineFlag("dump_timings");
	ci.useOpenCL = !args.CheckCmdLineFlag("disable_opencl");
	ci.m_useConcaveMesh = true;//args.CheckCmdLineFlag("use_concave_mesh");
	if (ci.m_useConcaveMesh)
	{
		enableExperimentalCpuConcaveCollision = true;
	}

	args.GetCmdLineArgument("cl_device", ci.preferredOpenCLDeviceIndex);
	args.GetCmdLineArgument("cl_platform", ci.preferredOpenCLPlatformIndex);
	args.GetCmdLineArgument("x_dim", ci.arraySizeX);
	args.GetCmdLineArgument("y_dim", ci.arraySizeY);
	args.GetCmdLineArgument("z_dim", ci.arraySizeZ);
	args.GetCmdLineArgument("x_gap", ci.gapX);
	args.GetCmdLineArgument("y_gap", ci.gapY);
	args.GetCmdLineArgument("z_gap", ci.gapZ);



	#ifndef B3_NO_PROFILE
	b3ProfileManager::Reset();
#endif //B3_NO_PROFILE


	window = new b3gDefaultOpenGLWindow();

	b3gWindowConstructionInfo wci(g_OpenGLWidth,g_OpenGLHeight);

	window->createWindow(wci);
	window->setResizeCallback(MyResizeCallback);
	window->setMouseMoveCallback(MyMouseMoveCallback);
	window->setMouseButtonCallback(MyMouseButtonCallback);
	window->setKeyboardCallback(MyKeyboardCallback);

	window->setWindowTitle("Bullet 3.x GPU Rigid Body http://bulletphysics.org");
	printf("-----------------------------------------------------\n");


#ifndef __APPLE__
	glewInit();
#endif

	gui = new GwenUserInterface();

    printf("started GwenUserInterface");


	GLPrimitiveRenderer prim(g_OpenGLWidth,g_OpenGLHeight);

	stash = initFont(&prim);


	gui->init(g_OpenGLWidth,g_OpenGLHeight,stash,window->getRetinaScale());

    printf("init fonts");


	gui->setToggleButtonCallback(MyButtonCallback);

	gui->registerToggleButton(MYPAUSE,"Pause");
	gui->registerToggleButton(MYPROFILE,"Profile");
	gui->registerToggleButton(MYRESET,"Reset");






	int numItems = sizeof(allDemos)/sizeof(ParticleDemo::CreateFunc*);
	demoNames.clear();
	for (int i=0;i<numItems;i++)
	{
		GpuDemo* demo = allDemos[i]();
		demoNames.push_back(demo->getName());
		delete demo;
	}

	gui->registerComboBox(MYCOMBOBOX1,numItems,&demoNames[0]);
	gui->setComboBoxCallback(MyComboBoxCallback);



	do
	{
		bool syncOnly = false;
		gReset = false;




	static bool once=true;




	glClearColor(1,0,0,1);
	glClear(GL_COLOR_BUFFER_BIT);

	{

		window->startRendering();
		glFinish();

		


		float color[4] = {1,1,1,1};
		prim.drawRect(0,0,200,200,color);
		float retinaScale = 1;

		  float x = 10;
            float y=220;
            float  dx=0;
            if (1)
            {
                B3_PROFILE("font sth_draw_text");

				glEnable(GL_BLEND);
				GLint err = glGetError();
				assert(err==GL_NO_ERROR);

				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
				err = glGetError();
				assert(err==GL_NO_ERROR);

				glDisable(GL_DEPTH_TEST);
				err = glGetError();
				assert(err==GL_NO_ERROR);


				glDisable(GL_CULL_FACE);

                sth_begin_draw(stash);
                sth_flush_draw(stash);
                sth_draw_text(stash, droidRegular,20.f, x, y, "Non-retina font rendering !@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,1);//retinaScale);
                if (retinaScale!=1.f)
                    sth_draw_text(stash, droidRegular,20.f*retinaScale, x, y+20, "Retina font rendering!@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,retinaScale);
                sth_flush_draw(stash);

                sth_end_draw(stash);
            }

		gui->draw(g_OpenGLWidth,g_OpenGLHeight);
		window->endRendering();
		glFinish();
	}
	once=false;

//	OpenGL3CoreRenderer render;

	glClearColor(0,1,0,1);
	glClear(GL_COLOR_BUFFER_BIT);

	window->endRendering();

	glFinish();



	window->setWheelCallback(b3DefaultWheelCallback);




	{
		GpuDemo* demo = allDemos[selectedDemo]();
//		demo->myinit();
		bool useGpu = false;


		int maxObjectCapacity=128*1024;

		ci.m_instancingRenderer = new GLInstancingRenderer(maxObjectCapacity);//render.getInstancingRenderer();
		ci.m_window = window;
		ci.m_gui = gui;
		ci.m_instancingRenderer->init();
		ci.m_instancingRenderer->InitShaders();
		ci.m_primRenderer = &prim;
//		render.init();

		demo->initPhysics(ci);



		

		printf("-----------------------------------------------------\n");

		FILE* csvFile = 0;
		FILE* detailsFile = 0;

		if (benchmark)
		{
			gPause = false;
			char prefixFileName[1024];
			char csvFileName[1024];
			char detailsFileName[1024];

			b3OpenCLDeviceInfo info;
			b3OpenCLUtils::getDeviceInfo(demo->getInternalData()->m_clDevice,&info);
			
			//todo: move this time stuff into the Platform/Window class
#ifdef _WIN32
			SYSTEMTIME time;
			GetLocalTime(&time);
			char buf[1024];
			DWORD dwCompNameLen = 1024;
			if (0 != GetComputerName(buf, &dwCompNameLen))
			{
				printf("%s", buf);
			} else
			{
				printf("unknown", buf);
			}

			sprintf(prefixFileName,"%s_%s_%s_%d_%d_%d_date_%d-%d-%d_time_%d-%d-%d",info.m_deviceName,buf,demoNames[selectedDemo],ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,time.wDay,time.wMonth,time.wYear,time.wHour,time.wMinute,time.wSecond);
			
#else
			timeval now;
			gettimeofday(&now,0);
			
			struct tm* ptm;
			ptm = localtime (&now.tv_sec);
			char buf[1024];
#ifdef __APPLE__
			sprintf(buf,"MacOSX");
#else
			sprintf(buf,"Unix");
#endif
			sprintf(prefixFileName,"%s_%s_%s_%d_%d_%d_date_%d-%d-%d_time_%d-%d-%d",info.m_deviceName,buf,demoNames[selectedDemo],ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,
					ptm->tm_mday,
					ptm->tm_mon+1,
					ptm->tm_year+1900,
					ptm->tm_hour,
					ptm->tm_min,
					ptm->tm_sec);
			
#endif

			sprintf(csvFileName,"%s.csv",prefixFileName);
			sprintf(detailsFileName,"%s.txt",prefixFileName);
			printf("Open csv file %s and details file %s\n", csvFileName,detailsFileName);

			//GetSystemTime(&time2);

			csvFile=fopen(csvFileName,"w");
			detailsFile = fopen(detailsFileName,"w");
			if (detailsFile)
				defaultOutput = detailsFile;

			//if (f)
			//	fprintf(f,"%s (%dx%dx%d=%d),\n",  g_deviceName,ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,ci.arraySizeX*ci.arraySizeY*ci.arraySizeZ);
		}

		
		fprintf(defaultOutput,"Demo settings:\n");
		fprintf(defaultOutput,"  SelectedDemo=%d, demoname = %s\n", selectedDemo, demo->getName());
		fprintf(defaultOutput,"  x_dim=%d, y_dim=%d, z_dim=%d\n",ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ);
		fprintf(defaultOutput,"  x_gap=%f, y_gap=%f, z_gap=%f\n",ci.gapX,ci.gapY,ci.gapZ);
		fprintf(defaultOutput,"\nOpenCL settings:\n");
		fprintf(defaultOutput,"  Preferred cl_device index %d\n", ci.preferredOpenCLDeviceIndex);
		fprintf(defaultOutput,"  Preferred cl_platform index%d\n", ci.preferredOpenCLPlatformIndex);
		fprintf(defaultOutput,"\n");

		b3OpenCLUtils::printPlatformInfo( demo->getInternalData()->m_platformId);
		fprintf(defaultOutput,"\n");
		b3OpenCLUtils::printDeviceInfo( demo->getInternalData()->m_clDevice);
		fprintf(defaultOutput,"\n");
		do
		{
			GLint err = glGetError();
			assert(err==GL_NO_ERROR);

			b3ProfileManager::Reset();
			b3ProfileManager::Increment_Frame_Counter();

//			render.reshape(g_OpenGLWidth,g_OpenGLHeight);
			ci.m_instancingRenderer->resize(g_OpenGLWidth,g_OpenGLHeight);
			prim.setScreenSize(g_OpenGLWidth,g_OpenGLHeight);

			window->startRendering();

			glClearColor(0.6,0.6,0.6,1);
			glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
			glEnable(GL_DEPTH_TEST);


			if (!gPause)
			{
				B3_PROFILE("clientMoveAndDisplay");

				demo->clientMoveAndDisplay();
			}
			else
			{

			}

			{
				B3_PROFILE("renderScene");
				demo->renderScene();
			}
			err = glGetError();
			assert(err==GL_NO_ERROR);


			/*if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getNumCollisionObjects())
			{
				B3_PROFILE("renderPhysicsWorld");
				b3AlignedObjectArray<b3CollisionObject*> arr = demo->getDynamicsWorld()->getCollisionObjectArray();
				b3CollisionObject** colObjArray = &arr[0];

				render.renderPhysicsWorld(demo->getDynamicsWorld()->getNumCollisionObjects(),colObjArray, syncOnly);
				syncOnly = true;

			}
			*/
			{
				B3_PROFILE("gui->draw");
				gui->draw(g_OpenGLWidth,g_OpenGLHeight);
			}
			err = glGetError();
			assert(err==GL_NO_ERROR);

			{
				B3_PROFILE("window->endRendering");
				window->endRendering();
			}
			err = glGetError();
			assert(err==GL_NO_ERROR);

			{
				B3_PROFILE("glFinish");
			}

			

			if (dump_timings)
			{
				b3ProfileManager::dumpAll(stdout);
			}

			if (csvFile)
			{
				static int frameCount=0;

				if (frameCount>0)
				{
					DumpSimulationTime(csvFile);
					if (detailsFile)
					{
							fprintf(detailsFile,"\n==================================\nFrame %d:\n", frameCount);
							b3ProfileManager::dumpAll(detailsFile);
					}
				}

				if (frameCount>=102)
					window->setRequestExit();
				frameCount++;
			}



		} while (!window->requestedExit() && !gReset);


		demo->exitPhysics();
		b3ProfileManager::CleanupMemory();
		delete demo;
		if (detailsFile)
		{
			fclose(detailsFile);
			detailsFile=0;
		}
		if (csvFile)
		{
			fclose(csvFile);
			csvFile=0;
		}
	}



	} while (gReset);


	gui->setComboBoxCallback(0);
	delete gui;
	gui=0;

	window->closeWindow();
	delete window;
	window = 0;

	return 0;
}
Example #13
0
void widget_list_draw(widget *w)
{
	if(!w)return;
	float height = 0.0f;
	float fascend=0, fdescend=0;
	sth_vmetrics(stash, w->fontface, w->fontsize, &fascend, &fdescend, &height);
	float hoff = -fascend;
	float fullheight = (float)w->count * height;
	float totalheight = (fullheight - (float)w->size.y) / fullheight;
	int y = 0;
	char **names = (char**)w->data;
	widget_rect_draw(w);

	glEnable(GL_SCISSOR_TEST);
	glScissor(w->drawpos.x, vid_height - w->drawpos.y - w->size.y, w->size.x, w->size.y);


	glColor4f(1,1,1,1);
	sth_begin_draw(stash);
	if( fullheight < w->size.y )
	{	// scrollbar not needed
		for(int i=0; i<w->count; i++)
		{
			if(i == w->selected)
			{
				glTranslatef(0, y, 0);
				glColor4f(1,1,1,0.2);
				draw_rect(w->size.x, height);
				glTranslatef(0, -y, 0);
			}
			glColor4f(1,1,1,1);
			sth_draw_text(stash, w->fontface, w->fontsize, 10, y+hoff, names[i], 0);
			y -= height;
		}
		sth_end_draw(stash);
	}
	else
	{
		float smooth = (float)w->count * (w->percent * totalheight);
		double mtmp = 0;
		int ysmooth = modf(smooth, &mtmp) * height;

		int i = smooth;
		for(; i<w->count; i++)
		{
			if(i == w->selected)
			{
				glTranslatef(0, y+ysmooth, 0);
				glColor4f(1,1,1,0.2);
				draw_rect(w->size.x-20, height);
				glTranslatef(0, -(y+ysmooth), 0);
			}
			glColor4f(1,1,1,1);
			sth_draw_text(stash, w->fontface, w->fontsize, 10, y+hoff+ysmooth, names[i], 0);
			y -= height;
			if( -y > w->size.y)
				break;
		}
		sth_end_draw(stash);
		glColor4f(0,0,0,0.5);
		glTranslatef(w->size.x - 20, 0, 0);
		draw_rect(20, w->size.y);
		glColor4f(1,1,1,0.9);

		float scrollfactor = w->size.y / fullheight;
		float barheight = scrollfactor * w->size.y;

		glTranslatef(0, -w->percent*(float)(w->size.y-barheight), 0);
		draw_rect(20, barheight);
		glTranslatef(0, w->percent*(float)(w->size.y-barheight), 0);

		glTranslatef(-w->size.x + 20, 0, 0);
	}
	glDisable(GL_SCISSOR_TEST);
}
Example #14
0
void widget_window_draw(widget *w)
{
	GLfloat colour=0.4f;
	glColor4f(0.0f, 0.0f, 0.0f, 0.6f);
	draw_rect(w->size.x, w->size.y);
	glColor4f(colour, colour, colour, 1.0f);
	glTranslatef(0, -5, 0);
	draw_rect(w->size.x, -3);

//	glTranslatef(0, -30, 0);

	glTranslatef(0, -25, 0);

	glColor4f(1,1,1,1);
	sth_begin_draw(stash);
	sth_draw_text(stash, 2,24.0f, 20, 7, w->data, 0);
	sth_draw_text(stash, 1,14.0f, w->size.x - 35, 10, "END", 0);
	sth_end_draw(stash);
//	glTranslatef(0, 0, 0);
	glColor4f(colour, colour, colour, 1.0f);
	draw_rect(w->size.x, -2);
	glTranslatef(0, 30, 0);

	glColor4f(0.5f, 0.5f, 0.2f, 0.4f);
	switch(w->clicked)
	{
	case 2:		// dragging
		glTranslatef(0, -5, 0);
		draw_rect(w->size.x, 23);
		glTranslatef(0, 5, 0);
		break;

	case 3:		// end button
		glTranslatef(w->size.x, -5, 0);
		draw_rect(-50, 23);
		glTranslatef(-w->size.x, 5, 0);
		break;

	case 4:		// resize bottom
		glTranslatef(0, -w->size.y, 0);
		draw_rect(w->size.x, -10);
		glTranslatef(0, w->size.y, 0);
		break;

	case 5:		// resize bottom left
		glTranslatef(0, -w->size.y, 0);
		draw_rect(10, -10);
		glTranslatef(0, w->size.y, 0);
		break;

	case 6:		// resize bottom right
		glTranslatef(w->size.x, -w->size.y, 0);
		draw_rect(-10, -10);
		glTranslatef(-w->size.x, w->size.y, 0);
		break;

	case 7:		// resize left
		draw_rect(10, w->size.y);
		break;

	case 8:		// resize right
		glTranslatef(w->size.x, 0, 0);
		draw_rect(-10, w->size.y);
		glTranslatef(-w->size.x, 0, 0);
		break;

	}

}
Example #15
0
int main(int argc, char* argv[])
{
		
	CommandLineArgs args(argc,argv);

	if (args.CheckCmdLineFlag("help"))
	{
		Usage();
		return 0;
	}

	args.GetCmdLineArgument("enable_interop", useInterop);
	printf("useInterop=%d\n",useInterop);



	args.GetCmdLineArgument("pause_simulation", pauseSimulation);
	printf("pause_simulation=%d\n",pauseSimulation);
	args.GetCmdLineArgument("x_dim", NUM_OBJECTS_X);
	args.GetCmdLineArgument("y_dim", NUM_OBJECTS_Y);
	args.GetCmdLineArgument("z_dim", NUM_OBJECTS_Z);

	args.GetCmdLineArgument("x_gap", X_GAP);
	args.GetCmdLineArgument("y_gap", Y_GAP);
	args.GetCmdLineArgument("z_gap", Z_GAP);
	printf("x_dim=%d, y_dim=%d, z_dim=%d\n",NUM_OBJECTS_X,NUM_OBJECTS_Y,NUM_OBJECTS_Z);
	printf("x_gap=%f, y_gap=%f, z_gap=%f\n",X_GAP,Y_GAP,Z_GAP);
	
	args.GetCmdLineArgument("enable_static", keepStaticObjects);
	printf("enable_static=%d\n",keepStaticObjects);	

	
	char* tmpfile = 0;
	args.GetCmdLineArgument("load_bulletfile", tmpfile );
	if (tmpfile)
		fileName = tmpfile;

	printf("load_bulletfile=%s\n",fileName);

	
	printf("\n");
#ifdef __APPLE__
	MacOpenGLWindow* window = new MacOpenGLWindow();
	window->init(g_OpenGLWidth,g_OpenGLHeight);
#else
	Win32OpenGLWindow* window = new Win32OpenGLWindow();
	btgWindowConstructionInfo wci;
	wci.m_width = g_OpenGLWidth;
	wci.m_height = g_OpenGLHeight;
	
	window->createWindow(wci);
	window->setWindowTitle("render test");

#endif
	
	

    float retinaScale = 1;
    
#ifndef __APPLE__
	GLenum err = glewInit();
#else
    retinaScale = window->getRetinaScale();
#endif
    
    window->runMainLoop();
	window->startRendering();
	window->endRendering();

	int maxObjectCapacity=128*1024;
	GLInstancingRenderer render(maxObjectCapacity);

	
	sth_stash* stash = initFont();
		
	render.InitShaders();


	createSceneProgrammatically(render);
    

	render.writeTransforms();

    window->runMainLoop();

	window->setMouseButtonCallback(MyMouseButtonCallback);
	window->setMouseMoveCallback(MyMouseMoveCallback);
	window->setResizeCallback(MyResizeCallback);
	window->setKeyboardCallback(btDefaultKeyboardCallback);
    window->setWheelCallback(btDefaultWheelCallback);


    GLPrimitiveRenderer* pprender = new GLPrimitiveRenderer(g_OpenGLWidth,g_OpenGLHeight);
   
   glUseProgram(0); 

////////////////////////////////
	setupGUI(g_OpenGLWidth,g_OpenGLHeight,stash,retinaScale);

	/////////////////////////////////////


	if (pCanvas)
	{
		pCanvas->SetSize(g_OpenGLWidth,g_OpenGLHeight);
	}

	class CProfileIterator* m_profileIterator;
	m_profileIterator = CProfileManager::Get_Iterator();

	glClearColor(1,1,1,1);
	while (!window->requestedExit())
	{
		CProfileManager::Reset();
	
		{
		BT_PROFILE("loop");

		if (shootObject)
		{
			shootObject = false;
			
			btVector3 linVel;// = (m_cameraPosition-m_cameraTargetPosition).normalize()*-100;

			int x,y;
			window->getMouseCoordinates(x,y);
			render.getMouseDirection(&linVel[0],x,y);
			linVel.normalize();
			linVel*=100;

//			btVector3 startPos;
			
			float orn[4] = {0,0,0,1};
			float pos[4];
			render.getCameraPosition(pos);
			
//			demo.setObjectTransform(pos,orn,0);
			//render.writeSingleInstanceTransformToGPU(pos,orn,0);
//			createScene(render, demo);
//			printf("numPhysicsInstances= %d\n", demo.m_numPhysicsInstances);
//			printf("numDynamicPhysicsInstances= %d\n", demo.m_numDynamicPhysicsInstances);
//			render.writeTransforms();
		}



		{
			BT_PROFILE("startRendering");
			window->startRendering();
		}
		render.RenderScene();
		glFinish();
		float col[4]={0,1,0,1};
	//	pprender->drawRect(10,50,120,60,col);
//             glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
		//glEnable(GL_TEXTURE_2D);
    
            float x = 10;
            float y=220;
            float  dx=0;
            if (0)
            {
                BT_PROFILE("font sth_draw_text");
                
                sth_begin_draw(stash);
                sth_flush_draw(stash);
                sth_draw_text(stash, droidRegular,20.f, x, y, "Non-retina font rendering !@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,1);//retinaScale);
                if (retinaScale!=1.f)
                    sth_draw_text(stash, droidRegular,20.f*retinaScale, x, y+20, "Retina font rendering!@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,retinaScale);
                sth_flush_draw(stash);
                
                sth_end_draw(stash);
            }
    
			if (1)
		{
			BT_PROFILE("gwen RenderCanvas");
	
			if (pCanvas)
			{
				glEnable(GL_BLEND);
				GLint err = glGetError();
				assert(err==GL_NO_ERROR);

				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		
				err = glGetError();
				assert(err==GL_NO_ERROR);

				err = glGetError();
				assert(err==GL_NO_ERROR);
        
				glDisable(GL_DEPTH_TEST);
				err = glGetError();
				assert(err==GL_NO_ERROR);
        
				//glColor4ub(255,0,0,255);
		
				err = glGetError();
				assert(err==GL_NO_ERROR);
        
		
				err = glGetError();
				assert(err==GL_NO_ERROR);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

			//	saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight);
			
				err = glGetError();
				assert(err==GL_NO_ERROR);

			
				err = glGetError();
				assert(err==GL_NO_ERROR);

				glDisable(GL_CULL_FACE);

				glDisable(GL_DEPTH_TEST);
				err = glGetError();
				assert(err==GL_NO_ERROR);

				err = glGetError();
				assert(err==GL_NO_ERROR);
            
				glEnable(GL_BLEND);

            
				err = glGetError();
				assert(err==GL_NO_ERROR);
            
 
            
				pCanvas->RenderCanvas();
				//restoreOpenGLState();
			}

		}

            
       
        

            
		window->endRendering();

		}


		
		CProfileManager::Increment_Frame_Counter();



		static bool printStats  = true;

		
		 if (printStats && !pauseSimulation)
		 {
			static int count = 0;
			count--;
			if (count<0)
			{
				count = 100;
				{
					//BT_PROFILE("processProfileData");
					processProfileData(m_profileIterator,false);
				}
				//CProfileManager::dumpAll();
				//printStats  = false;
			} else
			{
//				printf(".");
			}
		 }
		

	}

	delete pprender;
//	render.CleanupShaders();
#ifdef _WIN32
	window->closeWindow();
#else
	window->exit();
#endif

	delete window;
	
	
	
	return 0;


}
Example #16
0
int main(int argc, char* argv[])
{
	GLint err;
   b3CommandLineArgs args(argc,argv);

	if (args.CheckCmdLineFlag("help"))
	{
		Usage();
		return 0;
	}

	args.GetCmdLineArgument("enable_interop", useInterop);
	printf("useInterop=%d\n",useInterop);



	args.GetCmdLineArgument("pause_simulation", pauseSimulation);
	printf("pause_simulation=%d\n",pauseSimulation);
	

	
	char* tmpfile = 0;
	args.GetCmdLineArgument("load_bulletfile", tmpfile );
	if (tmpfile)
		fileName = tmpfile;

	printf("load_bulletfile=%s\n",fileName);

	int width = 700;
	int height= 512;
	printf("\n");
	
	
	b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
	window->createWindow(b3gWindowConstructionInfo(width,height));
	window->setWindowTitle("font test");
	
	

#ifndef __APPLE__
	err = glewInit();
#endif
    window->runMainLoop();
    
    loadShader();
    
    loadBufferData();
    
    initTestTexture();
    
	window->startRendering();
	window->endRendering();

	
    err = glGetError();
    b3Assert(err==GL_NO_ERROR);
    
		
//	render.InitShaders();
  
//	render.writeTransforms();

    window->runMainLoop();

//	window->setMouseCallback(b3DefaultMouseCallback);
//	window->setKeyboardCallback(b3DefaultKeyboardCallback);
  //  window->setWheelCallback(b3DefaultWheelCallback);

    err = glGetError();
    b3Assert(err==GL_NO_ERROR);


		int done;
	struct sth_stash* stash = 0;
	FILE* fp = 0;
	int datasize;

	float sx,sy,dx,dy,lh;
	int droidRegular;//, droidItalic, droidBold, droidJapanese, dejavu;
	GLuint texture;


	int fontTextureWidth = 512;
	int fontTextureHeight = 512;
	SimpleOpenGL2RenderCallbacks* renderCallbacks = new SimpleOpenGL2RenderCallbacks(&sData);

	stash = sth_create(fontTextureWidth,fontTextureHeight,renderCallbacks);
	
    err = glGetError();
    b3Assert(err==GL_NO_ERROR);
    
	if (!stash)
	{
		fprintf(stderr, "Could not create stash.\n");
		return -1;
	}

	// Load the first truetype font from memory (just because we can).
#ifdef _WIN32
    const char* fontPath = "../../bin/";
#else
    const char* fontPath = "./";
#endif
    
    char fullFontFileName[1024];
    sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Regular.ttf");//cour.ttf");//times.ttf");//DroidSerif-Regular.ttf");
	//sprintf(fullFontFileName,"%s%s",fontPath,"arial.ttf");//cour.ttf");//times.ttf");//DroidSerif-Regular.ttf");
    
	fp = fopen(fullFontFileName, "rb");
#ifdef LOAD_FONT_FROM_FILE
		unsigned char* data;
    err = glGetError();
    b3Assert(err==GL_NO_ERROR);
    
    b3Assert(fp);
    if (fp)
    {
        fseek(fp, 0, SEEK_END);
        datasize = (int)ftell(fp);
        fseek(fp, 0, SEEK_SET);
        data = (unsigned char*)malloc(datasize);
        if (data == NULL)
        {
            b3Assert(0);
            return -1;
        }
        else
            fread(data, 1, datasize, fp);
        fclose(fp);
        fp = 0;
    }
	if (!(droidRegular = sth_add_font_from_memory(stash, data)))
    {
        b3Assert(0);
        return -1;
    }
    err = glGetError();
    b3Assert(err==GL_NO_ERROR);

	// Load the remaining truetype fonts directly.
    sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Italic.ttf");

	if (!(droidItalic = sth_add_font(stash,fullFontFileName)))
	{
        b3Assert(0);
        return -1;
    }
     sprintf(fullFontFileName,"%s%s",fontPath,"DroidSerif-Bold.ttf");

	
	if (!(droidBold = sth_add_font(stash,fullFontFileName)))
	{
        b3Assert(0);
        return -1;
    }
    err = glGetError();
    b3Assert(err==GL_NO_ERROR);
    
     sprintf(fullFontFileName,"%s%s",fontPath,"DroidSansJapanese.ttf");
    if (!(droidJapanese = sth_add_font(stash,fullFontFileName)))
	{
        b3Assert(0);
        return -1;
    }
    err = glGetError();
    b3Assert(err==GL_NO_ERROR);
#else//LOAD_FONT_FROM_FILE
	char* data2 = OpenSansData;
	unsigned char* data = (unsigned char*) data2;
	if (!(droidRegular = sth_add_font_from_memory(stash, data)))
	{
		printf("error!\n");
	}
#endif//LOAD_FONT_FROM_FILE
	


	while (!window->requestedExit())
	{
        GLint err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
       // glClearColor(0.5f,0.5f,0.5f,1.f);
        
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
        window->startRendering();
		
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
		glClearColor(1,1,1,1);//.4, .4, 0.4, 1.0);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        //display();
      
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
    if (1)
	{
		B3_PROFILE("font stash rendering");
				// Update and render
		glEnable(GL_BLEND);
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);

		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);

        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
		glDisable(GL_DEPTH_TEST);
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
		//glColor4ub(255,0,0,255);
		
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
        glEnable(GL_BLEND);
		
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
		sx = 0; sy = height;
		
		sth_begin_draw(stash);
		
		display();

		dx = sx; dy = sy;
		static int once=0;


		//sth_draw_text(stash, droidRegular,12.f, dx, dy-50, "How does this OpenGL True Type font look? ", &dx,width,height);
		int spacing = 512;
		if (1)
		for (int i=20;i<=110;i+=12)
		{
			char txt[512];
			sprintf(txt,"%d. The quick brown fox jumped over the lazy dog. 1234567890",i);
				sth_draw_text(stash, droidRegular,i, 10, dy-spacing, txt, &dx,width,height);
				spacing-=i;
		}
		
		  err = glGetError();
                b3Assert(err==GL_NO_ERROR);

		if (0)
		for (int i=0;i<1;i++)
		{
			dx = sx;
			if (once!=1)
			{
				//need to save this file as UTF-8 without signature, codepage 650001 in Visual Studio
			    err = glGetError();
                b3Assert(err==GL_NO_ERROR);

				//sth_draw_text(stash, droidJapanese,16.f, dx, dy-36, (const char*) "\xE7\xA7\x81\xE3\x81\xAF\xE3\x82\xAC\xE3\x83\xA9\xE3\x82\xB9\xE3\x82\x92\xE9\xA3\x9F\xE3\x81\xB9\xE3\x82\x89\xE3\x82\x8C\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82",&dx,
                //              width,height);//はabcdefghijlkmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-+=?/\][{}.,<>`~@#$%^", &dx);
//				sth_draw_text(stash, droidJapanese,32.f, dx, dy, (const char*) "私はガラスを食べられます。それは私を傷つけません。",&dx);//はabcdefghijlkmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-+=?/\][{}.,<>`~@#$%^", &dx);
				
				dx = sx;

                err = glGetError();
                b3Assert(err==GL_NO_ERROR);
				sth_flush_draw(stash);
				dx=0;			
				sth_draw_text(stash, droidRegular,14.f, dx, dy-80, "How does this OpenGL True Type font look? ", &dx,width,height);
				dx=0;
				dy-=30;

                //sth_draw_text(stash, droidRegular,16.f, dx, dy-80, "Profile How does this OpenGL True Type font look? ", &dx,width,height);
				dx=0;
				dy-=30;

                
				sth_draw_text(stash, droidRegular,16.f, dx, dy-80, "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", &dx,width,height);
				dx=0;
				dy-=30;
				sth_draw_text(stash, droidRegular,16.f, dx, dy-80, "!@#$%^abcdefghijklmnopqrstuvwxyz", &dx,width,height);

				dx=0;
			//	sth_draw_text(stash, droidRegular,16.f, dx, dy-42, "aph OpenGL Profile aCABCabdabcdefghijlkmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^", &dx,width,height);
				//sth_draw_text(stash, droidRegular,16.f, dx, dy-42, "aph OpenGL Profile aCABCabdabcdefghijlkmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^", &dx,width,height);

				sth_flush_draw(stash);
                err = glGetError();
                b3Assert(err==GL_NO_ERROR);


			}	else
			{
				dx = sx;
				dy = height;
			
                err = glGetError();
                b3Assert(err==GL_NO_ERROR);

                
				sth_draw_texture(stash, droidRegular, 16.f, 0, 0,width,height, "a", &dx);
                err = glGetError();
                b3Assert(err==GL_NO_ERROR);

				dumpTextureToPng(fontTextureWidth, fontTextureHeight,"newPic.png");


			}
			once++;
		}
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
		sth_end_draw(stash);
		
		glEnable(GL_DEPTH_TEST);
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
		//glFinish();
	}
        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        

		window->endRendering();

        err = glGetError();
        b3Assert(err==GL_NO_ERROR);
        
		{
			glFinish();
		}


		static bool printStats  = true;

		
		
		 if (printStats && !pauseSimulation)
		 {
			static int count = 0;
			count--;
			if (count<0)
			{
				count = 100;
//				b3ProfileManager::dumpAll();
				//printStats  = false;
			} else
			{
//				printf(".");
			}
		 }

		 err = glGetError();
	    b3Assert(err==GL_NO_ERROR);


	}

#ifdef _WIN32
	sth_delete(stash);
#ifdef LOAD_FONT_FROM_FILE
	free(data);
#endif //LOAD_FONT_FROM_FILE
#endif

//	render.CleanupShaders();
	window->closeWindow();
	delete window;
	
	return 0;

}
Example #17
0
int main(int argc, char* argv[])
{

	int sz = sizeof(b3Generic6DofConstraint);
	int sz2 = sizeof(b3Point2PointConstraint);
	int sz3 = sizeof(b3TypedConstraint);
	int sz4 = sizeof(b3TranslationalLimitMotor);
	int sz5 = sizeof(b3RotationalLimitMotor);
	int sz6 = sizeof(b3Transform);

	//b3OpenCLUtils::setCachePath("/Users/erwincoumans/develop/mycache");


	b3SetCustomEnterProfileZoneFunc(b3ProfileManager::Start_Profile);
	b3SetCustomLeaveProfileZoneFunc(b3ProfileManager::Stop_Profile);


	b3SetCustomPrintfFunc(myprintf);
	b3Vector3 test=b3MakeVector3(1,2,3);
	test.x = 1;
	test.y = 4;

    printf("main start");

	b3CommandLineArgs args(argc,argv);
	ParticleDemo::ConstructionInfo ci;

	if (args.CheckCmdLineFlag("help"))
	{
		Usage();
		return 0;
	}

	selectedDemo =  loadCurrentDemoEntry(sStartFileName);


	args.GetCmdLineArgument("selected_demo",selectedDemo);


	if (args.CheckCmdLineFlag("new_batching"))
	{
		useNewBatchingKernel = true;
	}
	bool benchmark=args.CheckCmdLineFlag("benchmark");
	args.GetCmdLineArgument("max_framecount",maxFrameCount);

	args.GetCmdLineArgument("shadowmap_size",shadowMapWorldSize);

	args.GetCmdLineArgument("shadowmap_resolution",shadowMapWidth);
	shadowMapHeight=shadowMapWidth;
	if (args.CheckCmdLineFlag("disable_shadowmap"))
	{
		useShadowMap = false;
	}

	args.GetCmdLineArgument("pair_benchmark_file",gPairBenchFileName);

	gDebugLauncherCL = args.CheckCmdLineFlag("debug_kernel_launch");

	dump_timings=args.CheckCmdLineFlag("dump_timings");
	ci.useOpenCL = !args.CheckCmdLineFlag("disable_opencl");
	ci.m_useConcaveMesh = true;//args.CheckCmdLineFlag("use_concave_mesh");
	if (ci.m_useConcaveMesh)
	{
		enableExperimentalCpuConcaveCollision = true;
	}
	ci.m_useInstancedCollisionShapes = !args.CheckCmdLineFlag("no_instanced_collision_shapes");
	args.GetCmdLineArgument("cl_device", ci.preferredOpenCLDeviceIndex);
	args.GetCmdLineArgument("cl_platform", ci.preferredOpenCLPlatformIndex);
	gAllowCpuOpenCL = args.CheckCmdLineFlag("allow_opencl_cpu");
	gUseLargeBatches = args.CheckCmdLineFlag("use_large_batches");

	gUseJacobi = args.CheckCmdLineFlag("use_jacobi");
	gUseDbvt = args.CheckCmdLineFlag("use_dbvt");
	gDumpContactStats = args.CheckCmdLineFlag("dump_contact_stats");
	gCalcWorldSpaceAabbOnCpu = args.CheckCmdLineFlag("calc_aabb_cpu");
	gUseCalculateOverlappingPairsHost = args.CheckCmdLineFlag("calc_pairs_cpu");
	gIntegrateOnCpu = args.CheckCmdLineFlag("integrate_cpu");
	gConvertConstraintOnCpu = args.CheckCmdLineFlag("convert_constraints_cpu");
	useUniformGrid = args.CheckCmdLineFlag("use_uniform_grid");




	args.GetCmdLineArgument("x_dim", ci.arraySizeX);
	args.GetCmdLineArgument("y_dim", ci.arraySizeY);
	args.GetCmdLineArgument("z_dim", ci.arraySizeZ);
	args.GetCmdLineArgument("x_gap", ci.gapX);
	args.GetCmdLineArgument("y_gap", ci.gapY);
	args.GetCmdLineArgument("z_gap", ci.gapZ);

	gPause = args.CheckCmdLineFlag("paused");

	gDebugForceLoadingFromSource = args.CheckCmdLineFlag("load_cl_kernels_from_disk");
	gDebugSkipLoadingBinary = args.CheckCmdLineFlag("disable_cached_cl_kernels");


#ifndef B3_NO_PROFILE
	b3ProfileManager::Reset();
#endif //B3_NO_PROFILE


	window = new b3gDefaultOpenGLWindow();

	b3gWindowConstructionInfo wci(g_OpenGLWidth,g_OpenGLHeight);

	window->createWindow(wci);
	window->setResizeCallback(MyResizeCallback);
	window->setMouseMoveCallback(MyMouseMoveCallback);
	window->setMouseButtonCallback(MyMouseButtonCallback);
	window->setKeyboardCallback(MyKeyboardCallback);

	window->setWindowTitle("Bullet 3.x GPU Rigid Body http://bulletphysics.org");
	printf("-----------------------------------------------------\n");




#ifndef __APPLE__
	glewInit();
#endif

	gui = new GwenUserInterface();

    printf("started GwenUserInterface");


	GLPrimitiveRenderer prim(g_OpenGLWidth,g_OpenGLHeight);

	stash = initFont(&prim);


	if (gui)
	{
		gui->init(g_OpenGLWidth,g_OpenGLHeight,stash,window->getRetinaScale());

		printf("init fonts");


		gui->setToggleButtonCallback(MyButtonCallback);

		gui->registerToggleButton(MYPAUSE,"Pause");
		gui->registerToggleButton(MYPROFILE,"Profile");
		gui->registerToggleButton(MYRESET,"Reset");

		int numItems = sizeof(allDemos)/sizeof(ParticleDemo::CreateFunc*);
		demoNames.clear();
		for (int i=0;i<numItems;i++)
		{
			GpuDemo* demo = allDemos[i]();
			demoNames.push_back(demo->getName());
			delete demo;
		}

		gui->registerComboBox(MYCOMBOBOX1,numItems,&demoNames[0],selectedDemo);
		gui->setComboBoxCallback(MyComboBoxCallback);
	}



	do
	{
		bool syncOnly = false;
		gReset = false;

			{
		GLint err;
		glEnable(GL_BLEND);
		err = glGetError();
		b3Assert(err==GL_NO_ERROR);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glDisable(GL_DEPTH_TEST);
		err = glGetError();
		b3Assert(err==GL_NO_ERROR);
		window->startRendering();
		glClearColor(1,1,1,1);
		glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);//|GL_STENCIL_BUFFER_BIT);
		glEnable(GL_DEPTH_TEST);

		sth_begin_draw(stash);
		//sth_draw_text(stash, droidRegular,12.f, dx, dy-50, "How does this OpenGL True Type font look? ", &dx,width,height);
		int spacing = 0;//g_OpenGLHeight;
		float sx,sy,dx,dy,lh;
		sx = 0;
		sy = g_OpenGLHeight;
		dx = sx; dy = sy;
		//if (1)
		const char* msg[] = {"Please wait, initializing the OpenCL demo",
			"Please make sure to run the demo on a high-end discrete GPU with OpenCL support",
			"The first time it can take a bit longer to compile the OpenCL kernels.",
			"Check the console if it takes longer than 1 minute or if a demos has issues.",
			"Please share the full commandline output when reporting issues:",
			"App_Bullet3_OpenCL_Demos_* >> error.log",

			"",
			"",
#ifdef _DEBUG
			"Some of the demos load a large .obj file,",
			"please use an optimized build of this app for faster parsing",

			"",
			"",
#endif
			"You can press F1 to create a single screenshot,",
			"or press F2 toggle screenshot (useful to create movies)",
			"",
			"",
			"There are various command-line options such as --benchmark",
			"See http://github.com/erwincoumans/bullet3 for more information"
		};
		int fontSize = 68;

		int nummsg = sizeof(msg)/sizeof(const char*);
		for (int i=0;i<nummsg;i++)
		{
			char txt[512];
			sprintf(txt,"%s",msg[i]);
				//sth_draw_text(stash, droidRegular,i, 10, dy-spacing, txt, &dx,g_OpenGLWidth,g_OpenGLHeight);
				sth_draw_text(stash, droidRegular,fontSize, 10, spacing, txt, &dx,g_OpenGLWidth,g_OpenGLHeight);
				spacing+=fontSize;
			fontSize = 32;
		}

		sth_end_draw(stash);
		sth_flush_draw(stash);
		window->endRendering();
	}



	static bool once=true;


	//glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
	glClearColor(1,1,1,1);
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	window->setWheelCallback(b3DefaultWheelCallback);




	{
		GpuDemo* demo = allDemos[selectedDemo]();
		sDemo = demo;
//		demo->myinit();
		bool useGpu = false;


		//int maxObjectCapacity=128*1024;
		int maxObjectCapacity=1024*1024;
		maxObjectCapacity = b3Max(maxObjectCapacity,ci.arraySizeX*ci.arraySizeX*ci.arraySizeX+10);

		{
		ci.m_instancingRenderer = new GLInstancingRenderer(maxObjectCapacity);//render.getInstancingRenderer();
		ci.m_window = window;
		ci.m_gui = gui;
		ci.m_instancingRenderer->init();
		ci.m_instancingRenderer->resize(g_OpenGLWidth,g_OpenGLHeight);
		ci.m_instancingRenderer->InitShaders();
		ci.m_primRenderer = &prim;
//		render.init();
		}

		{
			demo->initPhysics(ci);
		}





		printf("-----------------------------------------------------\n");

		FILE* csvFile = 0;
		FILE* detailsFile = 0;

		if (benchmark)
		{

			char prefixFileName[1024];
			char csvFileName[1024];
			char detailsFileName[1024];

			b3OpenCLDeviceInfo info;
			b3OpenCLUtils::getDeviceInfo(demo->getInternalData()->m_clDevice,&info);

			//todo: move this time stuff into the Platform/Window class
#ifdef _WIN32
			SYSTEMTIME time;
			GetLocalTime(&time);
			char buf[1024];
			DWORD dwCompNameLen = 1024;
			if (0 != GetComputerName(buf, &dwCompNameLen))
			{
				printf("%s", buf);
			} else
			{
				printf("unknown", buf);
			}

			sprintf(prefixFileName,"%s_%s_%s_%d_%d_%d_date_%d-%d-%d_time_%d-%d-%d",info.m_deviceName,buf,demoNames[selectedDemo],ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,time.wDay,time.wMonth,time.wYear,time.wHour,time.wMinute,time.wSecond);

#else
			timeval now;
			gettimeofday(&now,0);

			struct tm* ptm;
			ptm = localtime (&now.tv_sec);
			char buf[1024];
#ifdef __APPLE__
			sprintf(buf,"MacOSX");
#else
			sprintf(buf,"Unix");
#endif
			sprintf(prefixFileName,"%s_%s_%s_%d_%d_%d_date_%d-%d-%d_time_%d-%d-%d",info.m_deviceName,buf,demoNames[selectedDemo],ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,
					ptm->tm_mday,
					ptm->tm_mon+1,
					ptm->tm_year+1900,
					ptm->tm_hour,
					ptm->tm_min,
					ptm->tm_sec);

#endif

			sprintf(csvFileName,"%s.csv",prefixFileName);
			sprintf(detailsFileName,"%s.txt",prefixFileName);
			printf("Open csv file %s and details file %s\n", csvFileName,detailsFileName);

			//GetSystemTime(&time2);

			csvFile=fopen(csvFileName,"w");
			detailsFile = fopen(detailsFileName,"w");
			if (detailsFile)
				defaultOutput = detailsFile;

			//if (f)
			//	fprintf(f,"%s (%dx%dx%d=%d),\n",  g_deviceName,ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ,ci.arraySizeX*ci.arraySizeY*ci.arraySizeZ);
		}


		fprintf(defaultOutput,"Demo settings:\n");
		fprintf(defaultOutput,"  SelectedDemo=%d, demoname = %s\n", selectedDemo, demo->getName());
		fprintf(defaultOutput,"  x_dim=%d, y_dim=%d, z_dim=%d\n",ci.arraySizeX,ci.arraySizeY,ci.arraySizeZ);
		fprintf(defaultOutput,"  x_gap=%f, y_gap=%f, z_gap=%f\n",ci.gapX,ci.gapY,ci.gapZ);
		fprintf(defaultOutput,"\nOpenCL settings:\n");
		fprintf(defaultOutput,"  Preferred cl_device index %d\n", ci.preferredOpenCLDeviceIndex);
		fprintf(defaultOutput,"  Preferred cl_platform index%d\n", ci.preferredOpenCLPlatformIndex);
		fprintf(defaultOutput,"\n");

		if (demo->getInternalData()->m_platformId)
		{
			b3OpenCLUtils::printPlatformInfo( demo->getInternalData()->m_platformId);
			fprintf(defaultOutput,"\n");
			b3OpenCLUtils::printDeviceInfo( demo->getInternalData()->m_clDevice);
			fprintf(defaultOutput,"\n");
		}
		do
		{


			GLint err = glGetError();
			assert(err==GL_NO_ERROR);


			if (exportFrame || exportMovie)
			{

				if (!renderTexture)
				{
					renderTexture = new GLRenderToTexture();
					GLuint renderTextureId;
					glGenTextures(1, &renderTextureId);

					// "Bind" the newly created texture : all future texture functions will modify this texture
					glBindTexture(GL_TEXTURE_2D, renderTextureId);

					// Give an empty image to OpenGL ( the last "0" )
					//glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_UNSIGNED_BYTE, 0);
					//glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA32F, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_FLOAT, 0);
					glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA32F, g_OpenGLWidth,g_OpenGLHeight, 0,GL_RGBA, GL_FLOAT, 0);

					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
					glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
					//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
					//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

					renderTexture->init(g_OpenGLWidth,g_OpenGLHeight,renderTextureId, RENDERTEXTURE_COLOR);
				}

				bool result = renderTexture->enable();
			}

			err = glGetError();
			assert(err==GL_NO_ERROR);

			b3ProfileManager::Reset();
			b3ProfileManager::Increment_Frame_Counter();

//			render.reshape(g_OpenGLWidth,g_OpenGLHeight);
			ci.m_instancingRenderer->resize(g_OpenGLWidth,g_OpenGLHeight);
			prim.setScreenSize(g_OpenGLWidth,g_OpenGLHeight);

			err = glGetError();
			assert(err==GL_NO_ERROR);

			window->startRendering();

			err = glGetError();
			assert(err==GL_NO_ERROR);

			glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);//|GL_STENCIL_BUFFER_BIT);
			glEnable(GL_DEPTH_TEST);

			err = glGetError();
			assert(err==GL_NO_ERROR);

			if (!gPause)
			{
				B3_PROFILE("clientMoveAndDisplay");

				demo->clientMoveAndDisplay();
			}
			else
			{

			}

			{
				B3_PROFILE("renderScene");
				demo->renderScene();
			}
			err = glGetError();
			assert(err==GL_NO_ERROR);


			/*if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getNumCollisionObjects())
			{
				B3_PROFILE("renderPhysicsWorld");
				b3AlignedObjectArray<b3CollisionObject*> arr = demo->getDynamicsWorld()->getCollisionObjectArray();
				b3CollisionObject** colObjArray = &arr[0];

				render.renderPhysicsWorld(demo->getDynamicsWorld()->getNumCollisionObjects(),colObjArray, syncOnly);
				syncOnly = true;

			}
			*/


			if (exportFrame || exportMovie)
			{

				char fileName[1024];
				sprintf(fileName,"screenShot%d.png",frameIndex++);
				writeTextureToPng(g_OpenGLWidth,g_OpenGLHeight,fileName);
				exportFrame = false;
				renderTexture->disable();
			}


			{
				B3_PROFILE("gui->draw");
				if (gui && gDrawGui)
					gui->draw(g_OpenGLWidth,g_OpenGLHeight);
			}
			err = glGetError();
			assert(err==GL_NO_ERROR);


			{
				B3_PROFILE("window->endRendering");
				window->endRendering();
			}

			err = glGetError();
			assert(err==GL_NO_ERROR);

			{
				B3_PROFILE("glFinish");
			}



			if (dump_timings)
			{
				b3ProfileManager::dumpAll(stdout);
			}

			if (csvFile)
			{
				static int frameCount=0;

				if (frameCount>0)
				{
					DumpSimulationTime(csvFile);
					if (detailsFile)
					{
							fprintf(detailsFile,"\n==================================\nFrame %d:\n", frameCount);
							b3ProfileManager::dumpAll(detailsFile);
					}
				}

				if (frameCount>=maxFrameCount)
					window->setRequestExit();
				frameCount++;
			}


			if (gStep)
				gPause=true;

		} while (!window->requestedExit() && !gReset);


		demo->exitPhysics();
		b3ProfileManager::CleanupMemory();
		delete ci.m_instancingRenderer;

		delete demo;
		sDemo = 0;

		if (detailsFile)
		{
			fclose(detailsFile);
			detailsFile=0;
		}
		if (csvFile)
		{
			fclose(csvFile);
			csvFile=0;
		}
	}



	} while (gReset);


	if (gui)
		gui->setComboBoxCallback(0);

	{



		delete gui;
		gui=0;

		exitFont();


		window->closeWindow();
		delete window;
		window = 0;

	}

	return 0;
}
Example #18
0
void gui_http_draw(void)
{
	if(!http_accepting_new_clients)return;

	float shade = 0.1;

	glColor4f(shade,shade,shade,0.5);
	int x = 20;
	int y = vid_height - 200;

	int min_w = 10;

	char stop[] = "Stop accepting connections";

	float x1, x2, y1, y2;
	sth_dim_text(stash, 3, 20.0f, stop, &x1, &y1, &x2, &y2);

	min_w = x2 - x1;


	for(int i=0; i< http_num_pending; i++)
	{
		sth_dim_text(stash, 3, 20.0f,
			http_get_name_pending(i), &x1, &y1, &x2, &y2);

		int tmp_w = x2 - x1;

		if(min_w < tmp_w)min_w = tmp_w;



	}

	min_w += 20;

	glLoadIdentity();
	glTranslatef(x, y, 0);

	draw_rect( min_w+20, 40 * (http_num_pending+1) + 20);
	glTranslatef(10, -10, 0);



	for(int i=0; i<= http_num_pending; i++)
	{
		draw_rect( min_w, 30);
		glTranslatef(0, -40, 0);
	}

	glLoadIdentity();
	glTranslatef(x, y, 0);


	sth_begin_draw(stash);
	glColor4f(1,1,1,1);
	sth_draw_text(stash, 3, 20, 20, -30, stop, 0);
	for(int i=0; i< http_num_pending; i++)
	{
		sth_draw_text(stash, 3, 20, 20, -i*40-70, http_get_name_pending(i), 0);
	}

	sth_end_draw(stash);

	glLoadIdentity();

}