コード例 #1
0
ファイル: render3d3.c プロジェクト: omer4d/SuperOldCode
int main()
{
 int exit = 0;
 int snum;
 LINE_LOOP *map = load_map("map.txt", &snum, 0.2);

 init();
 
 float cam_x = 0.0, cam_y = 2.0, cam_z = 30.0, cam_ax = 0.0, cam_ay = 0.0;

 printf("%d %d", sizeof(float), sizeof(float *));

 while(!exit)
  {
   VECTOR cam_dir = vector(SPEED * cos(M_PI * 0.5 - cam_ay * M_PI / 180.0), SPEED * sin(cam_ay * M_PI / 180.0 - M_PI * 0.5));

   int mx, my;
   get_mouse_mickeys(&mx, &my);
   //position_mouse(240, 320);
   
   cam_ay += mx * 0.03;
   cam_ax -= my * 0.03;
   if(cam_ax > 60) cam_ax = 60;
   if(cam_ax < -40) cam_ax = -40;
 
   if(keypressed())
    {
     if(key[KEY_ESC]) { exit = 1; }
     if(key[KEY_W]) { cam_x += cam_dir.x*10.0; cam_z += cam_dir.y*10.0; }
     if(key[KEY_S]) { cam_x -= cam_dir.x*10.0; cam_z -= cam_dir.y*10.0; }
     if(key[KEY_A]) { cam_x += cam_dir.y*10.0; cam_z += -cam_dir.x*10.0; }
     if(key[KEY_D]) { cam_x -= cam_dir.y*10.0; cam_z -= -cam_dir.x*10.0; }
     
     if(key[KEY_LEFT]) { cam_ay -= 0.09; }
     if(key[KEY_RIGHT]) { cam_ay += 0.09; }
     if(key[KEY_PGDN]) { cam_ax -= 0.09; }
     if(key[KEY_PGUP]) { cam_ax += 0.09; }
    }

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   transform(-cam_x, -cam_y, -cam_z, -cam_ax, cam_ay, 0.0);
   glBegin(GL_QUADS);

    glColor3ub(128, 128, 128); glVertex3f(-300.0, 0.0, 300.0);
     glVertex3f(300.0, 0.0, 300.0);
     glVertex3f(300.0, 0.0, -300.0);
     glVertex3f(-300.0, 0.0, -300.0);
   
   draw_map_3d(map, snum);
   glEnd();
   allegro_gl_flip();
  }

 free_map(map, snum);
 readkey();
 return 0;
}
コード例 #2
0
void AppMain()
{
	Vector3 camFr(0.476459, -0.334238, 0.813186);
	Vector3 camUp(00.168968, 0.942489, 0.288382);
	Vector3 camRi = camUp ^ camFr;
	Vector3 camPos(-6, 10, -13);

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(50,
				   (float)SCREEN_W / (float)SCREEN_H, // Aspect ratio
				   0.1, 1000); // Far plane

	while (!g_keys[KEY_ESC])
	{
		glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

		float camPosMag = camPos.Mag();
		float moveSpeed = 0.01f * camPosMag;
		int velx, vely;
		get_mouse_mickeys(&velx, &vely);
		if (mouse_b & 2)
		{
			camFr.RotateAroundY((float)-velx / 100.0f);
			camUp.RotateAroundY((float)-velx / 100.0f);
			camRi = camUp ^ camFr;
			camFr.RotateAround(camRi, (float)vely / 100.0f);
			camUp.RotateAround(camRi, (float)vely / 100.0f);
			moveSpeed *= 3.0f;
		}

		if (key[KEY_W])	camPos += camFr * moveSpeed;
		if (key[KEY_S])	camPos -= camFr * moveSpeed;
		if (key[KEY_A])	camPos += camRi * moveSpeed;
		if (key[KEY_D])	camPos -= camRi * moveSpeed;
		if (key[KEY_Q]) camPos.y -= moveSpeed;
		if (key[KEY_E]) camPos.y += moveSpeed;

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		Vector3 lookAtPos = camPos + camFr;
		gluLookAt(camPos.x, camPos.y, camPos.z,
				  lookAtPos.x, lookAtPos.y, lookAtPos.z,
				  camUp.x, camUp.y, camUp.z);
	
		DrawGrid(camPos);

		// *** Do the maths we actually want to test
		MainUserLoop();

		allegro_gl_flip();
	}

	return 0;
}
コード例 #3
0
ファイル: openglallegro.hpp プロジェクト: andryblack/guichan
 /**
  * Runs the OpenGL and Allegro application.
  */
 void run()
 {
     while(!key[KEY_ESC])
     {
         // Now we let the Gui object perform its logic.
         globals::gui->logic();
         // Now we let the Gui object draw itself.
         globals::gui->draw();
         
         // Now we draw the mouse cursor.
         allegro_gl_set_allegro_mode();
         show_mouse(screen);
         algl_draw_mouse();
         allegro_gl_unset_allegro_mode();
     
         // Finally we update the screen.
         allegro_gl_flip();
     }
 }
コード例 #4
0
ファイル: intro.cpp プロジェクト: Eliasvan/machineball
void showIntro(void)
{
	allegro_gl_begin();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, 800, 0, 600, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClearColor(0, 0, 0, 0);
	glShadeModel(GL_SMOOTH);
	glDepthFunc(GL_LEQUAL);
	glClearDepth(1.0);
	glEnable(GL_DEPTH_TEST);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_TEXTURE_2D);
	allegro_gl_end();

	GLuint machineballtex;
	allegro_gl_set_texture_format(GL_RGBA);
	BITMAP *bmp = create_bitmap_ex(32, 256, 64);
	blit(&mb_machineball_bmp, bmp, 0, 0, 0, 0, 256, 64);
	machineballtex = allegro_gl_make_masked_texture(bmp);
	destroy_bitmap(bmp);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

	dp = al_start_duh(menuduh, 2, 0, (float)options.musicvol/255.0, 2048, 22050);
	menumusicisplaying=1;

	timer.install();
	double time;
	time=0;
	while(!(key[KEY_ESC] || time>23))
	{
		rest(1);
		time=timer.seconds();

		al_poll_duh(dp);

		allegro_gl_begin();
		
		glLoadIdentity();
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		if(time<4)
		{
			glColor3f(time/4, time/4, time/4);
			text.print(120, 280, "BENNY KRAMEK PRESENTS");
			glBindTexture(GL_TEXTURE_2D, bennykramekwebtex);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(242, 180);
			glTexCoord2f(1, 0);
			glVertex2i(498, 180);
			glTexCoord2f(1, 1);
			glVertex2i(498, 212);
			glTexCoord2f(0, 1);
			glVertex2i(242, 212);
			glEnd();
		}
		else if(time<8)
		{
			glColor3f(1-((time-4)/4), 1-((time-4)/4), 1-((time-4)/4));
			text.print(120, 280, "BENNY KRAMEK PRESENTS");
			glBindTexture(GL_TEXTURE_2D, bennykramekwebtex);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(242, 180);
			glTexCoord2f(1, 0);
			glVertex2i(498, 180);
			glTexCoord2f(1, 1);
			glVertex2i(498, 212);
			glTexCoord2f(0, 1);
			glVertex2i(242, 212);
			glEnd();
		}

		glColor3f(0.5, 0.5, 0.5);
		text.begin();
		text.print(20, (int)(60*(time-8.7)),     "THIS IS THE FUTURE.");
		text.print(20, (int)(60*(time-8.7))-50,  "A FUTURE WHERE PRIMITIVE SPORTS");
		text.print(20, (int)(60*(time-8.7))-100, "NO LONGER EXIST. IN THIS WORLD,");
		text.print(20, (int)(60*(time-8.7))-150, "THERE IS ONLY ONE SPORT.");
		text.print(20, (int)(60*(time-8.7))-200, "THERE IS ONLY...");
		text.end();

		if(time>22 && time<=22.5)
		{
			glColor3f(1, 1, 1);
			glBindTexture(GL_TEXTURE_2D, machineballtex);
			glTranslatef(400, 300, 0);
			glScalef((time-22)*200, (time-22)*200, (time-22)*200);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(-4, -1);
			glTexCoord2f(1, 0);
			glVertex2i(4, -1);
			glTexCoord2f(1, 1);
			glVertex2i(4, 1);
			glTexCoord2f(0, 1);
			glVertex2i(-4, 1);
			glEnd();

		}
		if(time>22.5)
		{
			glColor3f(1, 1, 1);
			glBindTexture(GL_TEXTURE_2D, machineballtex);
			glTranslatef(400, 300+(time-22.5)*240, 0);
			glScalef(100-(time-22.5)*50, 100-(time-22.5)*50, 100-(time-22.5)*50);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex2i(-4, -1);
			glTexCoord2f(1, 0);
			glVertex2i(4, -1);
			glTexCoord2f(1, 1);
			glVertex2i(4, 1);
			glTexCoord2f(0, 1);
			glVertex2i(-4, 1);
			glEnd();
			glColor4f(1, 1, 1, 1-((time-22.5)));
			glLoadIdentity();
			glDisable(GL_TEXTURE_2D);
			glBegin(GL_QUADS);
			glVertex2i(0, 0);
			glVertex2i(800, 0);
			glVertex2i(800, 600);
			glVertex2i(0, 600);
			glEnd();
			glEnable(GL_TEXTURE_2D);
		}
		
		glFlush();
		allegro_gl_flip();
		allegro_gl_end();
	}

	glDeleteTextures(1, &machineballtex);
}
コード例 #5
0
ファイル: render3d2.c プロジェクト: omer4d/SuperOldCode
int main()
{
 int exit = 0;
 int snum;
 LINE_LOOP *map = load_map("map.txt", &snum, 0.2);

 init();
 glEnable(GL_LIGHTING);
  glShadeModel(GL_FLAT);
 float global_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);

glEnable(GL_LIGHT0);

// Create light components
float ambientLight[] = { 0.7f, 0.7f, 0.7f, 1.0f };
float diffuseLight[] = { 0.8f, 0.8f, 0.8, 1.0f };
float specularLight[] = { 0.0f, 0.0f, 0.0f, 1.0f };
float position[] = { -1.5f, 30.0f, 0.0f, 1.0f };

// Assign created components to GL_LIGHT0
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
//glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight);
glLightfv(GL_LIGHT0, GL_POSITION, position);

 
 float cam_x = 0.0, cam_y = 2.0, cam_z = 30.0, cam_ax = 0.0, cam_ay = 0.0;

 while(!exit)
  {
   VECTOR cam_dir = vector(SPEED * cos(M_PI * 0.5 - cam_ay * M_PI / 180.0), SPEED * sin(cam_ay * M_PI / 180.0 - M_PI * 0.5));

   int mx, my;
   get_mouse_mickeys(&mx, &my);
   //position_mouse(240, 320);
   
   cam_ay += mx * 0.03;
   cam_ax -= my * 0.03;
   if(cam_ax > 60) cam_ax = 60;
   if(cam_ax < -40) cam_ax = -40;
 
   if(keypressed())
    {
     if(key[KEY_ESC]) { exit = 1; }
     if(key[KEY_W]) { cam_x += cam_dir.x; cam_z += cam_dir.y; }
     if(key[KEY_S]) { cam_x -= cam_dir.x; cam_z -= cam_dir.y; }
     if(key[KEY_A]) { cam_x += cam_dir.y; cam_z += -cam_dir.x; }
     if(key[KEY_D]) { cam_x -= cam_dir.y; cam_z -= -cam_dir.x; }
     
     if(key[KEY_LEFT]) { cam_ay -= 0.09; }
     if(key[KEY_RIGHT]) { cam_ay += 0.09; }
     if(key[KEY_PGDN]) { cam_ax -= 0.09; }
     if(key[KEY_PGUP]) { cam_ax += 0.09; }
    }

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLightfv(GL_LIGHT0, GL_POSITION, position);
   transform(-cam_x, -cam_y, -cam_z, -cam_ax, cam_ay, 0.0);
   glBegin(GL_QUADS);

    glNormal3f(0.0, 1.0, 0.0);
    glColor3ub(255, 0, 0); glVertex3f(-300.0, 0.0, 300.0);
    glColor3ub(0, 255, 0); glVertex3f(300.0, 0.0, 300.0);
    glColor3ub(0, 0, 255); glVertex3f(300.0, 0.0, -300.0);
    glColor3ub(255, 255, 0); glVertex3f(-300.0, 0.0, -300.0);
   
   draw_map_3d(map, snum);
   glEnd();
   allegro_gl_flip();
  }

 free_map(map, snum);
 readkey();
 return 0;
}
コード例 #6
0
ファイル: test.c プロジェクト: AntonLanghoff/whitecatlib
void display (void)
{
	// Clear the RGB buffer and the depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Set the modelview matrix to be the identity matrix
	glLoadIdentity();
        
	//Set the camera
	glTranslatef (0, 0, -camera.dist);
	glRotatef (camera.xangle, 1, 0, 0);
	glRotatef (camera.yangle, 0, 1, 0);
	glRotatef (camera.zangle, 0, 0, 1);
	
	// Save the camera matrix
	glPushMatrix();
	
	// Translate and rotate the object
	glTranslatef(-2.5, 0.0, 0.0);
	glRotatef(-30, 1.0, 0.0, 0.0);
	glRotatef(30, 0.0, 1.0, 0.0);
	glRotatef(30, 0.0, 0.0, 1.0);

	glColor3f(1.0, 0.0, 1.0);

	// Draw the sides of the three-sided pyramid
	glBegin(GL_TRIANGLE_FAN);
			glVertex3d(0, 4, 0);
			glVertex3d(0, -4, -4);
			glVertex3d(-4, -4, 4);
			glVertex3d(4, -4, 4);
			glVertex3d(0, -4, -4);
	glEnd();

	glColor3f(0.0, 1.0, 1.0);

	// Draw the base of the pyramid
	glBegin(GL_TRIANGLES);
			glVertex3d(0, -4, -4);
			glVertex3d(4, -4, 4);
			glVertex3d(-4, -4, 4);
	glEnd();

	// Get the camera matrix back
	glPopMatrix();
	
	// Translate for the cube
	glTranslatef(2.5, 0.0, 0.0);
	glRotatef(45, 1.0, 0.0, 0.0);
	glRotatef(45, 0.0, 1.0, 0.0);
	glRotatef(45, 0.0, 0.0, 1.0);

	glColor3f(0.0, 1.0, 0.0);

	// Draw the sides of the cube
	glBegin(GL_QUAD_STRIP);
			glVertex3d(3, 3, -3);
			glVertex3d(3, -3, -3);
			glVertex3d(-3, 3, -3);
			glVertex3d(-3, -3, -3);
			glVertex3d(-3, 3, 3);
			glVertex3d(-3, -3, 3);
			glVertex3d(3, 3, 3);
			glVertex3d(3, -3, 3);
			glVertex3d(3, 3, -3);
			glVertex3d(3, -3, -3);
	glEnd();

	glColor3f(0.0, 0.0, 1.0);

	// Draw the top and bottom of the cube
	glBegin(GL_QUADS);
			glVertex3d(-3, -3, -3);
			glVertex3d(3, -3, -3);
			glVertex3d(3, -3, 3);
			glVertex3d(-3, -3, 3);

			glVertex3d(-3, 3, -3);
			glVertex3d(-3, 3, 3);
			glVertex3d(3, 3, 3);
			glVertex3d(3, 3, -3);
	glEnd();

	glFlush();

	allegro_gl_flip();

	frames++;
}
コード例 #7
0
ファイル: extext.c プロジェクト: AntonLanghoff/whitecatlib
int main() {

	FONT *lucidia_fnt;
	FONT *allegro_fnt;
	DATAFILE *dat;
	
	struct {
		float x, y, z;
		int c;
	} coord[NUM_STRINGS];
	char *string = STRING;
	int i;

	allegro_init();
	install_allegro_gl();
	install_timer();
	
	LOCK_FUNCTION(the_timer);
	LOCK_VARIABLE(chrono);
	
	install_int(the_timer, 2);

	allegro_gl_clear_settings();
	allegro_gl_set(AGL_COLOR_DEPTH, 32);
	allegro_gl_set(AGL_Z_DEPTH, 24);
	allegro_gl_set(AGL_WINDOWED, TRUE);
	allegro_gl_set(AGL_DOUBLEBUFFER, 1);
	allegro_gl_set(AGL_RENDERMETHOD, 1);
	allegro_gl_set(AGL_SUGGEST, AGL_COLOR_DEPTH | AGL_DOUBLEBUFFER
	             | AGL_RENDERMETHOD | AGL_Z_DEPTH | AGL_WINDOWED);

	if (set_gfx_mode(GFX_OPENGL, 640, 480, 0, 0)) {
		allegro_message("Error initializing OpenGL!\n");
		return -1;
	}

	install_keyboard();


	/* Load 2 copies of the datafile */	
	dat = load_datafile("lucidia.dat");

	if (!dat) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to load lucidia.dat\n");
		return -2;
	}

	lucidia_fnt = allegro_gl_convert_allegro_font((FONT*)dat[0].dat,
	                                              AGL_FONT_TYPE_TEXTURED, 16.0);

	if (!lucidia_fnt) {
		unload_datafile(dat);
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to convert font!\n");
		return -3;
	}

	allegro_fnt = allegro_gl_convert_allegro_font(font,
	                                              AGL_FONT_TYPE_TEXTURED, 16.0);

	if (!allegro_fnt) {
		allegro_gl_destroy_font(lucidia_fnt);
		unload_datafile(dat);
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to convert font!\n");
		return -4;
	}

	
	srand(time(NULL));


	for (i = 0; i < NUM_STRINGS; i++) {
		coord[i].z = 0;
		coord[i].c = 0;
	}
	i = 0;

	/* Start nice text demo */

	/* Setup OpenGL like we want */
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);

	glViewport(0, 0, SCREEN_W, SCREEN_H);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 60.0);

	/* Set culling mode - not that we have anything to cull */
	glEnable(GL_CULL_FACE);
	glFrontFace(GL_CCW);
			
	glMatrixMode(GL_MODELVIEW);

	do {
		int c;

		/* Update rotation angle of text */	
		glLoadIdentity();
		
		glTranslatef(0, 0, -30);
		glRotatef(-45, 1, 0, 0);
		glRotatef(-30, 0, 1, 0);

		/* Clear the screen and set a nice blender mode */
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);						
		glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);

		/* Print the text wheel */
		for (i = 0; i < NUM_STRINGS; i++) {			
			allegro_gl_printf(lucidia_fnt, coord[i].x, coord[i].y, coord[i].z,
			                  coord[i].c, string);
		}
		/* Update the text wheel's position */
		for (i = 0; i < NUM_STRINGS; i++) {
			int r, g, b;
			float angle2 = angle + i * M_PI * 2 / NUM_STRINGS;
			coord[i].x = 10 * cos(angle2) - 10;
			coord[i].y = 10 * sin(angle2);			
			angle2 = angle2 * 180.0 / M_PI;
#if ((((ALLEGRO_VERSION) << 16) | ((ALLEGRO_SUB_VERSION) << 8) | (ALLEGRO_WIP_VERSION)) == 0x40200)
			/* Work around an Allegro bug that's only in 4.2.0 */
			while (angle2 > 360.0f) angle2 -= 360.0f;
			while (angle2 < 0)      angle2 += 360.0f;
#endif			
			hsv_to_rgb(angle2, 1, 1, &r, &g, &b);
			coord[i].c = makeacol(r, g, b, 255);
		}
		/* Draw "AllegroGL" */
		glLoadIdentity();
		c = MID(0, (int)(255 - chrono / 100), 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING0) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 0, makecol(c, c, c), STRING0);
		c = MID(0, (int)(255 - chrono / 100) + 24, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING1) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 12, makecol(c, c, c), STRING1);
		c = MID(0, (int)(255 - chrono / 100) + 48, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING2) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 24, makecol(c, c, c), STRING2);
		c = MID(0, (int)(255 - chrono / 100) + 72, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING3) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 36, makecol(c, c, c), STRING3);
		c = MID(0, (int)(255 - chrono / 100) + 96, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(STRING4) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 48, makecol(c, c, c), STRING4);
		c = MID(0, (int)(255 - chrono / 100) + 120, 255);
		allegro_gl_printf(allegro_fnt, -(strlen(URL) * 1 / 2.0f) / 2,
		                -3.0f, -chrono / 200.0 + 60, makecol(c, c, c), URL);

		allegro_gl_flip();

		rest(2);

	} while (!key[KEY_ESC]);

	return 0;
}
コード例 #8
0
ファイル: c_simulation.cpp プロジェクト: rfree/antinet
void c_simulation::main_loop () {
	//	PALETTE palette;
	//BITMAP *img_bgr = load_bitmap("dat/bgr-bright.tga", NULL); // TODO:
    s_font_allegl.reset (allegro_gl_convert_allegro_font(font,AGL_FONT_TYPE_TEXTURED,500.0), [](FONT *f){allegro_gl_destroy_font(f);});

    for(auto &obj : m_world->m_objects) {
        obj->set_font(s_font_allegl);
    }
	int viewport_x = 0, viewport_y = 0;

	//show_mouse(m_screen);

	set_close_button_callback(c_close_button_handler);

	bool print_connect_line = false;
	bool start_simulation = false;
	bool simulation_pause = true;
	shared_ptr<c_cjddev> connect_node;
	std::chrono::steady_clock::time_point last_click_time =
		std::chrono::steady_clock::now() - std::chrono::milliseconds(1000);

	m_gui = make_shared<c_gui>();


	// prepare drawtarget surface to draw to
	switch (m_drawtarget_type) {
		case e_drawtarget_type_allegro:
			m_drawtarget = make_shared<c_drawtarget_allegro>(m_frame); 
		break;
		case e_drawtarget_type_opengl:
			m_drawtarget = make_shared<c_drawtarget_opengl>(); 
		break;
		default:
			_erro("Warning: unsupported drawtarget");
	}

	m_drawtarget->m_gui = m_gui;



	//	bool allegro_keys_any_was=false; // is any key pressed right now (for key press/release)
	long loop_miliseconds = 0;
	long unsigned int frame_checkpoint = 0; /// needed for speed control (without world_draw manipulate in spacetime!)
	_UNUSED(frame_checkpoint);

	bool use_input_allegro = true; // always for now.  input from Allegro
	bool use_draw_allegro = m_drawtarget_type == e_drawtarget_type_allegro; // draw in allegro
	bool use_draw_opengl = m_drawtarget_type == e_drawtarget_type_opengl; // draw in opengl


	_note("Entering main simulation loop");

	// The main drawing is done inside this loop.
	
	///@see rendering.txt/[[drawing_main]]
    float view_angle = 0.0;
    //float camera_offset = 1.0;

    float zoom = 1.0;
    float camera_step_z=-11.0;
    // === main loop ===
    while (!m_goodbye && !close_button_pressed) {

		auto start_time = std::chrono::high_resolution_clock::now();

		// --- process the keyboard/inputs ---
		if (use_input_allegro) {
				// TODO move this code here, but leave the variables in higher scope
		}

			poll_keyboard();
			auto allegro_keys = key;
			auto allegro_shifts = key_shifts;
			//		bool allegro_keys_any_is=false;
			//		for (size_t i=0; i<sizeof(allegro_keys)/sizeof(allegro_keys[0]); ++i) allegro_keys_any_is=true;
			// the direct raw position
			const int allegro_mouse_x = mouse_x;
			const int allegro_mouse_y = mouse_y;
			const int allegro_mouse_b = mouse_b; // buttons

			// the position in display port GUI
			const int gui_mouse_x = allegro_mouse_x; 
			const int gui_mouse_y = allegro_mouse_y;
			const int gui_mouse_b = allegro_mouse_b; // buttons
			
			// the position in the world coordinates
			const int gui_cursor_x = m_gui->view_x_rev(gui_mouse_x);
			const int gui_cursor_y = m_gui->view_y_rev(gui_mouse_y);
			const int gui_cursor_z = 0; // m_gui->view_z_rev(gui_mouse_z);
			
			_UNUSED(gui_mouse_b);
			_UNUSED(gui_cursor_x);
			_UNUSED(gui_cursor_y);
			_UNUSED(gui_cursor_z);

            //_dbg1("mouse_x mouse_y: " << gui_mouse_x << " " << gui_mouse_y);

			int allegro_char = 0;
			if (keypressed()) {
				allegro_char = readkey();
			}
		// end of input

		// draw background of frame
		if (use_draw_allegro) {
			clear_to_color(m_frame, makecol(0, 128, 0));
            blit(c_bitmaps::get_instance().m_background, m_frame, 0, 0, viewport_x, viewport_y, c_bitmaps::get_instance().m_background->w, c_bitmaps::get_instance().m_background->h);
		}
        if (use_draw_opengl) {
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
            //glDisable(GL_DEPTH_TEST);      // ??? Enables Depth Testing
            //glEnable(GL_DEPTH_TEST);
            //glDepthFunc(GL_LEQUAL);                         // The Type Of Depth Testing To Do
            //glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
             //glLoadIdentity();
            // glTranslatef(m_gui->camera_x, m_gui->camera_y,camera_offset);

            // minimum and maximum value for zoom in/out and rotate the scene
//            if (camera_offset >= 10.0) camera_offset = 10.0;
//            if (camera_offset <= 0.5) camera_offset = 0.5;
            if (view_angle >= 70) view_angle = 70;
            if(view_angle <= 0) view_angle = 0;

            if( zoom <= 0.1 ) zoom = 0.1;  //because of glFrustum -> when left=right, or bottom=top there's error GL_INVALID_VALUE, so we can't multiply e.g left,right by 0

            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            glFrustum(-1.0*zoom, 1.0*zoom, -1.0*zoom, 1.0*zoom, 1.0,60.0);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();

            //glTranslatef(0.0f,0.0f,-11.0);
            glTranslatef(0.0f,0.0f,camera_step_z);
            glRotatef(-view_angle, 1,0,0);
            glScalef(10,10,10);

            // drawing backgound
            glPushMatrix();
            //glScalef(1,1,1);
            glBindTexture(GL_TEXTURE_2D,c_bitmaps::get_instance().m_background_opengl);
            glEnable(GL_BLEND);
            //float q=1.0/zoom;
            float q=1.0;
            glBegin(GL_QUADS);
                glTexCoord2f(0,q); glVertex3f(-1.0f,1.0f, 0.0f);
                glTexCoord2f(q,q); glVertex3f(1.0f,1.0f, 0.0f);
                glTexCoord2f(q,0); glVertex3f(1.0f,-1.0f,0.0f);
                glTexCoord2f(0,0); glVertex3f(-1.0f,-1.0f,0.0f);
            glEnd();
            glDisable(GL_BLEND);
            glBindTexture(GL_TEXTURE_2D, 0);   // texture
            glPopMatrix();
		}
		
		// clear additional things
		if (use_draw_allegro) {
			clear_to_color(smallWindow, makecol(128, 128, 128));
		}

		// main controll keys
		if (allegro_keys[KEY_ESC]) {
			_note("User exits the simulation from user interface");
			m_goodbye = true;
		}

		if ((allegro_char & 0xff) == 'n' && !start_simulation) {
			std::cout << "ADD " << std::endl;
			_warn("THIS CODE IS NOT IMPLEMENTED NOW");
			/*
			m_world->m_objects.push_back(
				make_shared<c_cjddev>(
					cjddev_detail_random_name(), 
					// gui_mouse_x, gui_mouse_y,
					gui_cursor_x, gui_cursor_y,
					cjddev_detail_random_addr()));
					*/
		}

        if(allegro_keys[KEY_F1]){
            //auto ptr = get_move_object(gui_mouse_x,gui_mouse_y);


						//  TODO  -in allegro?   -not entire screen?    
						/*
            try{
                if(ptr != NULL){
                    int col_num =0;
                    textout_ex(smallWindow, font, ptr->get_name().c_str(), 0, 0, makecol(0, 0, 255), -1);

                        if(c_cjddev* tmp = dynamic_cast<c_cjddev *>(ptr.get()) ){
                            char* addr =(char *) malloc(45);
                             sprintf(addr,"address: %ld",tmp->get_address());
                             textout_ex(smallWindow, font,addr , 10, col_num+=10, makecol(0, 0, 255), -1);
                             sprintf(addr,"neighbors: %d",(int)tmp->get_neighbors().size());
                             textout_ex(smallWindow, font,addr , 10, col_num+=10, makecol(0, 0, 255), -1);
                             sprintf(addr,"waitng: %d",(int)tmp->num_of_wating());
                             textout_ex(smallWindow, font,addr , 10, col_num+=10, makecol(0, 0, 255), -1);

//                    		textout_ex(smallWindow, font, ptr->get_name().c_str(), 0, 0, makecol(0, 0, 255), -1);{
                            free (addr);
                        }

												if (use_draw_allegro) { 
													// draw the information window
                        	blit (smallWindow,m_frame,0,0,m_frame->w-200,m_frame->h-200,screen->w/8, screen->h/4);
												}

                    }
            }
						catch(...) {}
						*/

//            std::cout<<ptr->get_name().c_str()<<std::endl;
        }
				

        if(allegro_keys[KEY_F2]){
//            BITMAP* screen = gui_get_screen();
          int m_x =0;
          int m_y =0;
          static unsigned int num =0;
            if(num>=m_world->m_objects.size()){
                num=0;
            }
           try{

//                auto obj = m_world->m_objects.at(0);
//                m_x = m_world->m_objects.at(num)->get_x() - (screen->w/2);
//                m_y = m_world->m_objects.at(num)->get_y() - (screen->h/2);
                  m_x =  m_world->m_objects.at(num)->get_x()*m_gui->camera_zoom - (allegro_mouse_x);
                  m_y =  m_world->m_objects.at(num)->get_y()*m_gui->camera_zoom - (allegro_mouse_y);


                //    std::cout<< screen->w<<" "<<screen->h<<" "<<screen->x_ofs<<" "<<screen->y_ofs<<std::endl;

                    m_gui->camera_x = m_x ;
                    m_gui->camera_y = m_y;


                    std::this_thread::sleep_for(std::chrono::milliseconds(100));
                    num++;
            }catch(...)
            {

            }

        }


		// animation & tick
		if (m_frame_number % g_max_anim_frame == 0 && !simulation_pause) {
			frame_checkpoint = m_frame_number;
			m_world->tick(); // <===
		}


		// === main user interface ===

		// the mode
		typedef enum { e_mode_node, e_mode_camera } t_mode;
		t_mode mode;
		mode = e_mode_node; // by default we will move/edit etc the node (or entityt)
		if (allegro_shifts & KB_SHIFT_FLAG) mode = e_mode_camera; // with key SHIFT we move camera instea

		// mode: camera movement etc
		if (mode == e_mode_camera) {
			if (allegro_keys[KEY_LEFT]) m_gui->camera_x -= 10;
			if (allegro_keys[KEY_RIGHT]) m_gui->camera_x += 10;
            if (allegro_keys[KEY_UP]) m_gui->camera_y -= 10;
			if (allegro_keys[KEY_DOWN]) m_gui->camera_y += 10;

			const double zoom_speed = 1.1;
            if (allegro_keys[KEY_PGUP]) m_gui->camera_zoom *= zoom_speed;
			if (allegro_keys[KEY_PGDN]) m_gui->camera_zoom /= zoom_speed;
		}

        // rotate and zoom in/out the scene
        if(allegro_keys[KEY_Z]) {
            //camera_offset+=0.1;
            zoom+=0.1;
            _dbg1("zoom: " << zoom);
        }

        if(allegro_keys[KEY_X]) {
            //camera_offset-=0.1;
            zoom-=0.1;
            _dbg1("zoom: " << zoom);
        }
        if(allegro_keys[KEY_C]) {
            view_angle+=1.0;
            //farVal+=10;
            _dbg1("view_angle: " << view_angle);
        }
        if(allegro_keys[KEY_V]) {
            view_angle-=1.0;
            _dbg1("view_angle: " << view_angle);
        }
        if(allegro_keys[KEY_Q]) {
            camera_step_z+=0.1;
        }
        if(allegro_keys[KEY_W]) {
            camera_step_z -= 0.1;

            if(camera_step_z <= -11.0) camera_step_z=-11.0;
        }

		// === text debug on screen ===

		string mouse_pos_str = std::to_string(gui_mouse_x) + " " + std::to_string(gui_mouse_y);
		string fps_str = "fps ???";
		if (loop_miliseconds != 0) {
			fps_str = "fps: " + std::to_string(1000 / loop_miliseconds);
		}

		const int txt_h = 12; // line height (separation between lines)
		int txt_x = 10, txt_y = 10; // starting position of text

		if (use_draw_allegro) {

			string pck_speed_str = "sending packets speed - " + std::to_string(450 - g_max_anim_frame);
			textout_ex(m_frame, font, mouse_pos_str.c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1);
			textout_ex(m_frame, font, fps_str.c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1);
			textout_ex(m_frame, font, ("Frame nr.: " +
																 std::to_string(m_frame_number)).c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1);

			textout_ex(m_frame, font, pck_speed_str.c_str(), 100, 10, makecol(0, 0, 255), -1);

					if(allegro_keys[KEY_H])
			{
				int tex_y = 10;
				int lineh = 10;
				textout_ex(m_frame, font, "s - start", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
				textout_ex(m_frame, font, "p - pause", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
				textout_ex(m_frame, font, "f - send FTP", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
				textout_ex(m_frame, font, "t - select target", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
				textout_ex(m_frame, font, "r - select source", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
				textout_ex(m_frame, font, "d - remove node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
				textout_ex(m_frame, font, "n - add node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
				textout_ex(m_frame, font, "enter/esc - exit", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
				textout_ex(m_frame, font, "Arrows: move selected node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
				textout_ex(m_frame, font, "SHIFT-Arrows: move the camera", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
							textout_ex(m_frame, font, "SHIFT-PageUp/Down: zimm in/out", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
							textout_ex(m_frame, font, "F1: info about node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
							textout_ex(m_frame, font, "F2: next node", 1140, tex_y+=lineh, makecol(0, 0, 255), -1);
					} else{

							textout_ex(m_frame, font, "h - help", 1140, 30, makecol(0, 0, 255), -1);
					}
		}
		if (use_draw_opengl) {
			// TODO @opengl
            //textout_ex(m_frame, font, mouse_pos_str.c_str(), txt_x, txt_y += txt_h, makecol(0, 0, 255), -1);
            float offset = 0.03;
            float tex_y = 0.9;
            float tex_x = 0.7;
            string pck_speed_str = "sending packets speed - " + std::to_string(450 - g_max_anim_frame);
            glColor4f(0.0,0.0,1.0,0.0);
            //glScalef(0.2f,0.2f,0.2f);
            //glLoadIdentity();
            glPushMatrix();
            glEnable(GL_BLEND);
            allegro_gl_printf_ex(s_font_allegl.get(), -0.9, tex_y, 0.0, mouse_pos_str.c_str());
            allegro_gl_printf_ex(s_font_allegl.get(), -0.9, tex_y-=offset, 0.0, fps_str.c_str());
            allegro_gl_printf_ex(s_font_allegl.get(), -0.9, tex_y-=offset, 0.0, ("Frame nr.: " + std::to_string(m_frame_number)).c_str());
            allegro_gl_printf_ex(s_font_allegl.get(), -0.7, 0.97, 0.0, pck_speed_str.c_str());
            glDisable(GL_BLEND);
            glPopMatrix();

            if(allegro_keys[KEY_H]) {
                _dbg1("KEY_H - opengl");
                //glLoadIdentity();
                glPushMatrix();
                glEnable(GL_BLEND);
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y, 0.0,"s - start");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"p - pause");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"f - send FTP");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"t - select target");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"r - select source");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"d - remove node");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"n - add node");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"enter/esc - exit");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"Arrows: move selected node");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"SHIFT-Arrows: move the camera");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"SHIFT-PageUp/Down: zoom in/out");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"F1: info about node");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y-=offset, 0.0,"F2: next node");
                glDisable(GL_BLEND);
                glPopMatrix();

            } else {
                //glLoadIdentity();
                glPushMatrix();
                glEnable(GL_BLEND);
                //allegro_gl_printf(s_font_allegl.get(), 0.8, 0.9, 0.0,0xFF0000,"h - help");
                allegro_gl_printf_ex(s_font_allegl.get(), tex_x, tex_y, 0.0,"h - help");
                //glBlendFunc(GL_ONE, GL_ZERO);
                glDisable(GL_BLEND);
                glPopMatrix();
            }
		}


		//_dbg3("m_world->m_objects.size(): " << m_world->m_objects.size());
		//_dbg3("get_move_object ret: " << get_move_object(gui_mouse_x, gui_mouse_y));
		int move_object_index = get_move_object(gui_mouse_x, gui_mouse_y); ///< -1 if 'empty'

		if (move_object_index != -1) { // working with selected object
			m_gui->m_selected_object = m_world->m_objects.begin();
			std::advance(m_gui->m_selected_object, move_object_index);
			auto selected_object = m_gui->m_selected_object;
			(*selected_object)->m_selected = true;
			c_entity *selected_object_raw = dynamic_cast<c_entity *>((*selected_object).get());
			c_osi2_switch *selected_switch = dynamic_cast<c_osi2_switch *>((*selected_object).get());
			
		//	selected_switch->send_hello_to_neighbors(); // TODO
			
			//shared_ptr<c_cjddev> selected_device = std::dynamic_pointer_cast<c_cjddev>(selected_object);
			if (selected_object != m_world->m_objects.end()) { // editing the selected object
				// TODO: add connect
				/*if (gui_mouse_b == 1 && !print_connect_line) {
					print_connect_line = true;
					connect_node = std::dynamic_pointer_cast<c_cjddev>(selected_object);
					last_click_time = std::chrono::steady_clock::now();
				}

				if (gui_mouse_b == 1 && print_connect_line &&
				    std::chrono::steady_clock::now() - last_click_time > std::chrono::milliseconds(500)) {
					// assert( connect_node && selected_object  );
					connect_node->add_neighbor(std::dynamic_pointer_cast<c_cjddev>(selected_object));
					(std::dynamic_pointer_cast<c_cjddev>(selected_object))->add_neighbor(std::dynamic_pointer_cast<c_cjddev>(connect_node));
					print_connect_line = false;
				}*/

				if (mode == e_mode_node) { // working with selected object - moving
					if (!print_connect_line) {
						int speed = 5;
						if (allegro_keys[KEY_LEFT])
							selected_object_raw->m_x += -speed;
						if (allegro_keys[KEY_RIGHT])
							selected_object_raw->m_x += speed;
						if (allegro_keys[KEY_DOWN])
							selected_object_raw->m_y += speed;
						if (allegro_keys[KEY_UP])
							selected_object_raw->m_y += -speed;
					}
				} // moving selected object
			}
/*
			if ((allegro_char & 0xff) == 's' && !start_simulation) {
				if (!m_gui->m_source || !m_gui->m_target) {
					std::cout << "please choose target and source node\n";
				} else {
					m_gui->m_source->buy_net(m_gui->m_target->get_address());
					start_simulation = true;
					simulation_pause = false;
				}
			}

			if ((allegro_char & 0xff) == 'd' && selected_device && !start_simulation) {
				for (shared_ptr<c_cjddev> &it : selected_device->get_neighbors()) {
					selected_device->remove_neighbor(it);
					it->remove_neighbor(selected_device);
				}

				for (auto it = m_world->m_objects.begin(); it != m_world->m_objects.end(); ++it) {
					if (it->get() == selected_device.get()) {
						m_world->m_objects.erase(it);
						break;
					}
				}
			}

			if ((allegro_char & 0xff) == 't' && selected_device && !start_simulation) {
				m_gui->m_target = selected_device;
			}

			if ((allegro_char & 0xff) == 'r' && selected_device && !start_simulation) {
				m_gui->m_source = selected_device;
			}

			if ((allegro_char & 0xff) == 'f') {
				if (!m_gui->m_source || !m_gui->m_target)
					std::cout << "please choose target and source node\n";
				else {
					m_gui->m_source->send_ftp_packet(m_gui->m_target->get_address(), "FTP data");
					last_click_time = std::chrono::steady_clock::now();
				}
			}
*/

			// === animation clock controll ===
			if ((allegro_char & 0xff) == 'p') {
				simulation_pause = !simulation_pause;
				last_click_time = std::chrono::steady_clock::now();
			}

			if (allegro_keys[KEY_MINUS_PAD] && g_max_anim_frame < 400 &&
			    std::chrono::steady_clock::now() - last_click_time > std::chrono::milliseconds(loop_miliseconds)) {
				//std::cout << m_frame_number-frame_checkpoint << " - " << g_max_anim_frame << " mod: " << (m_frame_number-frame_checkpoint) % g_max_anim_frame <<  std::endl;
				g_max_anim_frame += 1;
				last_click_time = std::chrono::steady_clock::now();
			}

			if (allegro_keys[KEY_PLUS_PAD] && g_max_anim_frame > 10 &&
			    std::chrono::steady_clock::now() - last_click_time > std::chrono::milliseconds(loop_miliseconds)) {
				//std::cout << m_frame_number-frame_checkpoint << " + " << g_max_anim_frame << " mod: " << (m_frame_number-frame_checkpoint) % g_max_anim_frame <<  std::endl;
				g_max_anim_frame -= 1;
				last_click_time = std::chrono::steady_clock::now();
			}
			
		}

		// === animation clock operations ===
		
        m_world->draw(*m_drawtarget.get()); // <===== DRAW THE WORLD

		/*
		if ((m_frame_number - frame_checkpoint) < g_max_anim_frame) {
			m_world->draw(*m_drawtarget.get(), (m_frame_number - frame_checkpoint) % g_max_anim_frame); // <==
		} else {
			m_world->draw(*m_drawtarget.get(), g_max_anim_frame);
		}
		*/

		if (print_connect_line) { // the line the creates new connections
			if (use_draw_allegro) {
				line(m_frame, connect_node->m_x, connect_node->m_y, allegro_mouse_x, allegro_mouse_y, makecol(0, 255, 255));
			}
            // TODO @opengl
            if (use_draw_opengl) {
                glColor3f(0.0f,1.0f,1.0f);
                glLineWidth(1.0);
                glScalef(1.0f,1.0f,1.0f);

                const int vx = m_gui->view_x(connect_node->m_x), vy = m_gui->view_y(connect_node->m_y); // position in viewport - because camera position
                //float start_line_x = ((connect_node->m_x)-0.5*SCREEN_W)/(0.5*SCREEN_W);
                //float start_line_y = -((connect_node->m_y)-0.5*SCREEN_H)/(0.5*SCREEN_H);
                float start_line_x = (vx-0.5*SCREEN_W)/(0.5*SCREEN_W);
                float start_line_y = -(vy-0.5*SCREEN_H)/(0.5*SCREEN_H);
                float end_line_x = (allegro_mouse_x-0.5*SCREEN_W)/(0.5*SCREEN_W);
                float end_line_y = -(allegro_mouse_y-0.5*SCREEN_H)/(0.5*SCREEN_H);

                //_dbg1("connect_node: " << connect_node->m_x << " " << connect_node->m_y);
                //_dbg1("allegro_mouse: " << allegro_mouse_x << " " << allegro_mouse_y);
                //_dbg1("start_line: " << start_line_x << " " << start_line_y);
                //_dbg1("end_line: " << end_line_x << " " << end_line_y);

                //glLoadIdentity();
                glPushMatrix();
                glBegin(GL_LINES);
                glVertex3f(start_line_x,start_line_y,0.0f);
                glVertex3f(end_line_x,end_line_y,0.0f);
                glEnd();
                glPopMatrix();
            }
		}
		if (allegro_mouse_b == 2) { // end/stop the line that creates new connections
			print_connect_line = false;
		}




		{
			auto x = allegro_mouse_x, y = allegro_mouse_y;
			int r = 5, rr = 4;

			if (use_draw_allegro) {
				line(m_frame, x - rr, y, x + rr, y, makecol(0, 0, 0));
				line(m_frame, x, y - rr, x, y + rr, makecol(0, 0, 0));
				circle(m_frame, x, y, r, makecol(255, 255, 255));
			}
			// TODO @opengl
            if(use_draw_opengl) {
                float opengl_mouse_x = (x-SCREEN_W*0.5)/(0.5*SCREEN_W);
                float opengl_mouse_y = -(y-SCREEN_H*0.5)/(0.5*SCREEN_H);
                float cursor_size=0.01;

                //_dbg1("mouse_x mouse_y: " << mouse_x << " " << mouse_y);
                //_dbg1("screenW screenH: " << SCREEN_W << " " << SCREEN_H);
                //glLoadIdentity();
                //glScalef(1/camera_offset, 1/camera_offset, 1.0);
                //glScalef(1.0*zoom, 1.0*zoom, 1.0*zoom);
                glPushMatrix();
                glScalef(1.0f,1.0f,1.0f);
                glTranslatef(opengl_mouse_x,opengl_mouse_y,0.0f);
                //glTranslatef(m_gui->view_x_rev(mouse_x),m_gui->view_y_rev(mouse_y),0.0f);
                glColor3f(0.0, 0.0, 0.0);

                // draw cursor
                glBegin(GL_LINES);
                glVertex2f(-1.0f*cursor_size,0.0f);
                glVertex2f(1.0f*cursor_size,0.0f);
                glVertex2f(0.0f,-1.0f*cursor_size);
                glVertex2f(0.0f,1.0f*cursor_size);
                glEnd();
                glPopMatrix();
            }

		}


		// === show frame ===

		if (use_draw_allegro) {
			//_dbg1("Allegro: frame done. fps = " << fps_str);
			scare_mouse();
			blit(m_frame, m_screen, 0, 0, 0, 0, m_frame->w, m_frame->h);
			unscare_mouse();
			if (!simulation_pause) {
				++m_frame_number;
			}
		}
		if (use_draw_opengl) {
            //_dbg1("OpenGL: frame flip. fps = " << fps_str);
			allegro_gl_flip();
		}

		for (auto &object : m_world->m_objects) {
			object->m_selected = false;
		}
		
//		std::this_thread::sleep_for(std::chrono::milliseconds(10));
		auto stop_time = std::chrono::high_resolution_clock::now();
		auto diff = stop_time - start_time;
		loop_miliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(diff).count();
	}

	std::ofstream out_file("../layout/current/out.map.txt");
	out_file << *m_world << std::endl;
}
コード例 #9
0
ファイル: glBrush.c プロジェクト: omer4d/SuperOldCode
int main()
{
 int exit = 0, i;
 GLuint fbo, canvas, brush;

 init();

 VECTOR arm[ARM_NUMBER], arm_normal[ARM_NUMBER], center = vector(SCREEN_W / 2, SCREEN_H / 2), p, p1, p2;

 for(i = 0; i < ARM_NUMBER; i++)
  {
   arm[i].x = cos(i * 2.0 * M_PI / ARM_NUMBER);
   arm[i].y = sin(i * 2.0 * M_PI / ARM_NUMBER);
   arm_normal[i] = VECTOR_NORMAL(arm[i]);
  }

 glGenFramebuffersEXT(1, &fbo);
 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
 canvas = empty_texture(SCREEN_W, SCREEN_H);
 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, canvas, 0);

 brush = load_texture("brush.bmp", AGL_TEXTURE_MIPMAP, GL_RGB8);
 glBindTexture(GL_TEXTURE_2D, brush);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

 glEnable(GL_BLEND);
 glBlendFunc(GL_ONE, GL_ONE);
 //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

 while(!exit)
  {
   if(key[KEY_ESC]) { exit = 1; } 

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

   if(mouse_b == 1)
    {         
     glBindTexture(GL_TEXTURE_2D, brush);
     glColor3ub(rand() % 128, rand() % 128, rand() % 128);
     glBegin(GL_QUADS);
     p = vector(center.x - mouse_x, center.y - mouse_y);

     for(i = 0; i < ARM_NUMBER; i++)
      {
       p1 = VECTOR_SUM(USCALE_VECTOR(arm[i], p.x), USCALE_VECTOR(arm_normal[i], -p.y));
       p2 = VECTOR_SUM(USCALE_VECTOR(arm[i], p.x), USCALE_VECTOR(arm_normal[i], p.y));
       my_rect(vector(center.x + p1.x, center.y + p1.y), 5.0);
       my_rect(vector(center.x + p2.x, center.y + p2.y), 5.0);
      }

     glEnd();
    }

   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   glBindTexture(GL_TEXTURE_2D, canvas);
   glColor3f(1.0, 1.0, 1.0);
   glBegin(GL_QUADS);
    glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 0.0);
    glTexCoord2f(1.0, 1.0); glVertex2f(SCREEN_W, 0.0);
    glTexCoord2f(1.0, 0.0); glVertex2f(SCREEN_W, SCREEN_H);
    glTexCoord2f(0.0, 0.0); glVertex2f(0.0, SCREEN_H);
   glEnd();
   glBindTexture(GL_TEXTURE_2D, brush);
   glColor3ub(255, 0, 0);
   glBegin(GL_QUADS);
    my_rect(vector(mouse_x, mouse_y), 10.0);
   glEnd();

   allegro_gl_flip();
  }

 return 0;
}
コード例 #10
0
ファイル: render.cpp プロジェクト: Eliasvan/machineball
void render(void)
{
	int i;

	allegro_gl_begin();

	glClearColor(0.1, 0.2, 0.2, 1);
	glClear(GL_DEPTH_BUFFER_BIT);

	glLoadIdentity();
	const dReal * ballpos = dBodyGetPosition(ball.body);
	const dReal * machpos0 = dBodyGetPosition(machine[0].body[0]);
	const dReal * machpos1 = dBodyGetPosition(machine[1].body[0]);
	camera.adjust(ballpos[0], ballpos[1], machpos0[0], machpos0[1], machpos1[0], machpos1[1], camerazoomtime*court.x*2-50*camerazoomtime);
	GLfloat LightAmbient[]= { 0.7, 0.7, 0.7, 1.0 };
	GLfloat LightDiffuse[]= { 1.0, 1.0, 1.0, 1.0 };
	GLfloat LightPosition[]= { -300.0, -300.0, 1000.0, 1.0 };
	glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
	glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
	

	
	glEnable(GL_TEXTURE_2D);

	glBindTexture(GL_TEXTURE_2D, floortex);
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);

	glColor3f(0.8, 0.8, 0.8);
	glBegin(GL_QUADS);
	glTexCoord2f(0, 0);
	glVertex3f(-court.x-300, -court.y-300, 0);
	glTexCoord2f(10, 0);
	glVertex3f(court.x+300, -court.y-300, 0);
	glTexCoord2f(10, 10);
	glVertex3f(court.x+300, court.y+300, 0);
	glTexCoord2f(0, 10);
	glVertex3f(-court.x-300, court.y+300, 0);
	glEnd();

	glColor3f(1, 1, 1);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	
	glBindTexture(GL_TEXTURE_2D, floortex);
	glBegin(GL_QUADS);
	glNormal3f(0, 0, 1);
	glTexCoord2f(0, 0);
	glVertex3f(-court.x-30, -court.y, 0);
	glTexCoord2f(court.x/30, 0);
	glVertex3f(court.x+30, -court.y, 0);
	glTexCoord2f(court.x/30, court.y/30);
	glVertex3f(court.x+30, court.y, 0);
	glTexCoord2f(0, court.y/30);
	glVertex3f(-court.x-30, court.y, 0);
	glEnd();

	glDisable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);

	glBegin(GL_QUADS);

	glNormal3f(0, 0, 1);

	glVertex3f(-1, -court.y, 0);
	glVertex3f(1, -court.y, 0);
	glVertex3f(1, court.y, 0);
	glVertex3f(-1, court.y, 0);
	
	glVertex3f(-court.x, court.y/2, 0);
	glVertex3f(-court.x/1.5, court.y/2, 0);
	glVertex3f(-court.x/1.5, court.y/2-1, 0);
	glVertex3f(-court.x, court.y/2-1, 0);

	glVertex3f(-court.x, -court.y/2, 0);
	glVertex3f(-court.x/1.5, -court.y/2, 0);
	glVertex3f(-court.x/1.5, -court.y/2+1, 0);
	glVertex3f(-court.x, -court.y/2+1, 0);

	glVertex3f(-court.x/1.5, court.y/2, 0);
	glVertex3f(-court.x/1.5+1, court.y/2, 0);
	glVertex3f(-court.x/1.5+1, -court.y/2, 0);
	glVertex3f(-court.x/1.5, -court.y/2, 0);

	glVertex3f(court.x, court.y/2, 0);
	glVertex3f(court.x/1.5, court.y/2, 0);
	glVertex3f(court.x/1.5, court.y/2-1, 0);
	glVertex3f(court.x, court.y/2-1, 0);

	glVertex3f(court.x, -court.y/2, 0);
	glVertex3f(court.x/1.5, -court.y/2, 0);
	glVertex3f(court.x/1.5, -court.y/2+1, 0);
	glVertex3f(court.x, -court.y/2+1, 0);

	glVertex3f(court.x/1.5, court.y/2, 0);
	glVertex3f(court.x/1.5+1, court.y/2, 0);
	glVertex3f(court.x/1.5+1, -court.y/2, 0);
	glVertex3f(court.x/1.5, -court.y/2, 0);

	glVertex3f(-court.x-1, -35, 0);
	glVertex3f(-court.x, -35, 0);
	glVertex3f(-court.x, 35, 0);
	glVertex3f(-court.x-1, 35, 0);

	glVertex3f(court.x, -35, 0);
	glVertex3f(court.x+1, -35, 0);
	glVertex3f(court.x+1, 35, 0);
	glVertex3f(court.x, 35, 0);
	
	glEnd();

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, shadowtex);
	glDisable(GL_LIGHTING);
	glEnable(GL_BLEND);
	glColor4f(0, 0, 0, 0.6);
	glBegin(GL_QUADS);
	glTexCoord2f(0, 0);
	glVertex3f(ballpos[0]-ball.getRadius()*1.2, ballpos[1]-ball.getRadius()*1.2, 0);
	glTexCoord2f(1, 0);
	glVertex3f(ballpos[0]+ball.getRadius()*1.2, ballpos[1]-ball.getRadius()*1.2, 0);
	glTexCoord2f(1, 1);
	glVertex3f(ballpos[0]+ball.getRadius()*1.2, ballpos[1]+ball.getRadius()*1.2, 0);
	glTexCoord2f(0, 1);
	glVertex3f(ballpos[0]-ball.getRadius()*1.2, ballpos[1]+ball.getRadius()*1.2, 0);
	glEnd();
	glDisable(GL_BLEND);

	glEnable(GL_DEPTH_TEST);

	glBindTexture(GL_TEXTURE_2D, walltex);
	glColor3f(1, 1, 1);

	glBegin(GL_QUAD_STRIP);
	glTexCoord2f(0, 0);
	glVertex3f(-court.x+28.48581, court.y, 0);
	glTexCoord2f(0, 1);
	glVertex3f(-court.x+28.48581, court.y, 30);
	glTexCoord2f(15, 0);
	glVertex3f(court.x-28.48581, court.y, 0);
	glTexCoord2f(15, 1);
	glVertex3f(court.x-28.48581, court.y, 30);
	glTexCoord2f(16, 0);
	glVertex3f(court.x-14, court.y-6, 0);
	glTexCoord2f(16, 1);
	glVertex3f(court.x-14, court.y-6, 30);
	glTexCoord2f(17, 0);
	glVertex3f(court.x-6, court.y-14, 0);
	glTexCoord2f(17, 1);
	glVertex3f(court.x-6, court.y-14, 30);
	glTexCoord2f(18, 0);
	glVertex3f(court.x, court.y-28.48581, 0);
	glTexCoord2f(18, 1);
	glVertex3f(court.x, court.y-28.48581, 30);
	glTexCoord2f(21, 0);
	glVertex3f(court.x, 35, 0);
	glTexCoord2f(21, 1);
	glVertex3f(court.x, 35, 30);
	glTexCoord2f(23, 0);
	glVertex3f(court.x+30, 35, 0);
	glTexCoord2f(23, 1);
	glVertex3f(court.x+30, 35, 30);
	glTexCoord2f(25, 0);
	glVertex3f(court.x+30, -35, 0);
	glTexCoord2f(25, 1);
	glVertex3f(court.x+30, -35, 30);
	glTexCoord2f(27, 0);
	glVertex3f(court.x, -35, 0);
	glTexCoord2f(27, 1);
	glVertex3f(court.x, -35, 30);
	glTexCoord2f(29, 0);
	glVertex3f(court.x, -court.y+28.48581, 0);
	glTexCoord2f(29, 1);
	glVertex3f(court.x, -court.y+28.48581, 30);
	glTexCoord2f(32, 0);
	glVertex3f(court.x-6, -court.y+14, 0);
	glTexCoord2f(32, 1);
	glVertex3f(court.x-6, -court.y+14, 30);
	glTexCoord2f(33, 0);
	glVertex3f(court.x-14, -court.y+6, 0);
	glTexCoord2f(33, 1);
	glVertex3f(court.x-14, -court.y+6, 30);
	glTexCoord2f(34, 0);
	glVertex3f(court.x-28.48581, -court.y, 0);
	glTexCoord2f(34, 1);
	glVertex3f(court.x-28.48581, -court.y, 30);
	glTexCoord2f(49, 0);
	glVertex3f(-court.x+28.48581, -court.y, 0);
	glTexCoord2f(49, 1);
	glVertex3f(-court.x+28.48581, -court.y, 30);
	glTexCoord2f(50, 0);
	glVertex3f(-court.x+14, -court.y+6, 0);
	glTexCoord2f(50, 1);
	glVertex3f(-court.x+14, -court.y+6, 30);
	glTexCoord2f(51, 0);
	glVertex3f(-court.x+6, -court.y+14, 0);
	glTexCoord2f(51, 1);
	glVertex3f(-court.x+6, -court.y+14, 30);
	glTexCoord2f(52, 0);
	glVertex3f(-court.x, -court.y+28.48581, 0);
	glTexCoord2f(52, 1);
	glVertex3f(-court.x, -court.y+28.48581, 30);
	glTexCoord2f(54, 0);
	glVertex3f(-court.x, -35, 0);
	glTexCoord2f(54, 1);
	glVertex3f(-court.x, -35, 30);
	glTexCoord2f(56, 0);
	glVertex3f(-court.x-30, -35, 0);
	glTexCoord2f(56, 1);
	glVertex3f(-court.x-30, -35, 30);
	glTexCoord2f(59, 0);
	glVertex3f(-court.x-30, 35, 0);
	glTexCoord2f(59, 1);
	glVertex3f(-court.x-30, 35, 30);
	glTexCoord2f(61, 0);
	glVertex3f(-court.x, 35, 0);
	glTexCoord2f(61, 1);
	glVertex3f(-court.x, 35, 30);
	glTexCoord2f(63, 0);
	glVertex3f(-court.x, court.y-28.48581, 0);
	glTexCoord2f(63, 1);
	glVertex3f(-court.x, court.y-28.48581, 30);
	glTexCoord2f(64, 0);
	glVertex3f(-court.x+6, court.y-14, 0);
	glTexCoord2f(64, 1);
	glVertex3f(-court.x+6, court.y-14, 30);
	glTexCoord2f(65, 0);
	glVertex3f(-court.x+14, court.y-6, 0);
	glTexCoord2f(65, 1);
	glVertex3f(-court.x+14, court.y-6, 30);
	glTexCoord2f(66, 0);
	glVertex3f(-court.x+28.48581, court.y, 0);
	glTexCoord2f(66, 1);
	glVertex3f(-court.x+28.48581, court.y, 30);
	glEnd();
	glBegin(GL_QUAD_STRIP);
	glTexCoord2f(0, 0);
	glVertex3f(-court.x/3*2, court.y*2, 0);
	glTexCoord2f(0, 2);
	glVertex3f(-court.x/3*2, court.y*2, 200);
	glTexCoord2f(1, 0);
	glVertex3f(-court.x/3*2, court.y+40, 0);
	glTexCoord2f(1, 2);
	glVertex3f(-court.x/3*2, court.y*1.5+20, 200);
	glTexCoord2f(2, 0);
	glVertex3f(-court.x/3*1, court.y+40, 0);
	glTexCoord2f(2, 2);
	glVertex3f(-court.x/3*1, court.y*1.5+20, 200);
	glTexCoord2f(3, 0);
	glVertex3f(-court.x/3*1, court.y*2, 0);
	glTexCoord2f(3, 2);
	glVertex3f(-court.x/3*1, court.y*2, 200);
	glEnd();
	glBegin(GL_QUAD_STRIP);
	glTexCoord2f(0, 0);
	glVertex3f(court.x/3*2, court.y*2, 0);
	glTexCoord2f(0, 2);
	glVertex3f(court.x/3*2, court.y*2, 200);
	glTexCoord2f(1, 0);
	glVertex3f(court.x/3*2, court.y+40, 0);
	glTexCoord2f(1, 2);
	glVertex3f(court.x/3*2, court.y*1.5+20, 200);
	glTexCoord2f(2, 0);
	glVertex3f(court.x/3*1, court.y+40, 0);
	glTexCoord2f(2, 2);
	glVertex3f(court.x/3*1, court.y*1.5+20, 200);
	glTexCoord2f(3, 0);
	glVertex3f(court.x/3*1, court.y*2, 0);
	glTexCoord2f(3, 2);
	glVertex3f(court.x/3*1, court.y*2, 200);
	glEnd();
	glBegin(GL_QUAD_STRIP);
	glTexCoord2f(0, 0);
	glVertex3f(-court.x/3*2, -court.y*2, 0);
	glTexCoord2f(0, 2);
	glVertex3f(-court.x/3*2, -court.y*2, 200);
	glTexCoord2f(1, 0);
	glVertex3f(-court.x/3*2, -court.y-40, 0);
	glTexCoord2f(1, 2);
	glVertex3f(-court.x/3*2, -court.y*1.5-20, 200);
	glTexCoord2f(2, 0);
	glVertex3f(-court.x/3*1, -court.y-40, 0);
	glTexCoord2f(2, 2);
	glVertex3f(-court.x/3*1, -court.y*1.5-20, 200);
	glTexCoord2f(3, 0);
	glVertex3f(-court.x/3*1, -court.y*2, 0);
	glTexCoord2f(3, 2);
	glVertex3f(-court.x/3*1, -court.y*2, 200);
	glEnd();
	glBegin(GL_QUAD_STRIP);
	glTexCoord2f(0, 0);
	glVertex3f(court.x/3*2, -court.y*2, 0);
	glTexCoord2f(0, 2);
	glVertex3f(court.x/3*2, -court.y*2, 200);
	glTexCoord2f(1, 0);
	glVertex3f(court.x/3*2, -court.y-40, 0);
	glTexCoord2f(1, 2);
	glVertex3f(court.x/3*2, -court.y*1.5-20, 200);
	glTexCoord2f(2, 0);
	glVertex3f(court.x/3*1, -court.y-40, 0);
	glTexCoord2f(2, 2);
	glVertex3f(court.x/3*1, -court.y*1.5-20, 200);
	glTexCoord2f(3, 0);
	glVertex3f(court.x/3*1, -court.y*2, 0);
	glTexCoord2f(3, 2);
	glVertex3f(court.x/3*1, -court.y*2, 200);
	glEnd();

	
	glEnable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, balltex);
	glPushMatrix();
	position_gl(ball.body);
	glColor3f(0.5, 0.5, 0.5);
	draw_sphere(ball.getRadius(), 24);
	glPopMatrix();
	glEnable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, machinetex);
	glEnable(GL_CULL_FACE);
	for(i=0; i<2; i++)
	{
		glPushMatrix();
		position_gl(machine[i].body[0]);
		if(i==0)
			glColor3f(0.5, 0.3, 0.2);
		else
			glColor3f(0.5, 0.5, 0.5);
		bodymodel.render();
		if(machine[i].powerupcount>0 && machine[i].turbocount!=0)
		{
			glDisable(GL_TEXTURE_2D);
			glEnable(GL_BLEND);
			glDisable(GL_LIGHTING);
			glDisable(GL_CULL_FACE);
			glBegin(GL_QUADS);
			glColor4f(1, 0, 0, 0.7);
			glVertex3f(5.5, -12, 0);
			glVertex3f(3.5, -12, 0);
			glColor4f(1, 1, 0, 0);
			glVertex3f(4, -25, 0);
			glVertex3f(5, -25, 0);

			glColor4f(1, 0, 0, 0.7);
			glVertex3f(-3.5, -12, 0);
			glVertex3f(-5.5, -12, 0);
			glColor4f(1, 1, 0, 0);
			glVertex3f(-5, -25, 0);
			glVertex3f(-4, -25, 0);
			glEnd();
			glEnable(GL_CULL_FACE);
			glEnable(GL_LIGHTING);
			glDisable(GL_BLEND);
			glEnable(GL_TEXTURE_2D);
		}
		glPopMatrix();

		glPushMatrix();
		position_gl(machine[i].body[1]);
		if(machine[i].getEnergy()==4)
			glColor3f(0.5, 0.5, 0.5);
		else
			glColor3f(0.35, 0.3, 0.3);
		pushermodel.render();
		glPopMatrix();
	}
	glDisable(GL_CULL_FACE);
	glDisable(GL_LIGHTING);

	glBindTexture(GL_TEXTURE_2D, reflecttex);
	glEnable(GL_TEXTURE_GEN_S);
	glEnable(GL_TEXTURE_GEN_T);
	glColor3f(1, 1, 1);
	for(i=0; i<2; i++)
	{
		glPushMatrix();
		position_gl(machine[i].body[0]);
		glBegin(GL_QUADS);
		glNormal3f(0, 0.8, 0.4);
		glVertex3f(0, 7.4298439026, 1.25);
		glNormal3f(0, 0.7, 0.7);
		glVertex3f(0, 4.8880519867, 2.75);
		glNormal3f(0.6, 0.7, 0.7);
		glVertex3f(7.4881892204, 4.8880519867, 2.75);
		glNormal3f(0.6, 0.8, 0.4);
		glVertex3f(7.4881892204, 7.4298439026, 1.25);
		glNormal3f(0, 0.8, 0.4);
		glVertex3f(0, 7.4298439026, 1.25);
		glNormal3f(0, 0.7, 0.7);
		glVertex3f(0, 4.8880519867, 2.75);
		glNormal3f(-0.6, 0.7, 0.7);
		glVertex3f(-7.4881892204, 4.8880519867, 2.75);
		glNormal3f(-0.6, 0.8, 0.4);
		glVertex3f(-7.4881892204, 7.4298439026, 1.25);
		glEnd();
		glPopMatrix();
	}

	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);

	glEnable(GL_CULL_FACE);
	glDisable(GL_TEXTURE_2D);
	for(i=0; i<2; i++)
	{
		if(machine[i].shieldcount>0)
		{
			const dReal * pos0 = dBodyGetPosition(machine[i].body[0]);
			const dReal * pos1 = dBodyGetPosition(machine[i].body[1]);
			double length=sqrt(
					(pos0[0]-pos1[0])*(pos0[0]-pos1[0]) +
					(pos0[1]-pos1[1])*(pos0[1]-pos1[1]) +
					(pos0[2]-pos1[2])*(pos0[2]-pos1[2]))+3;
			glEnable(GL_BLEND);
			glEnable(GL_LIGHTING);
			glPushMatrix();
			position_gl(machine[i].body[0]);
			glColor4f(0, 1, 0, machine[i].shieldcount>1?((machine[i].shieldcount-(int)machine[i].shieldcount)/6.0+0.2):machine[i].shieldcount/2);
			glBegin(GL_QUADS);
			glNormal3f(0, 0, 1);
			glVertex3f(-12, -14, 6);
			glVertex3f(12, -14, 6);
			glVertex3f(12, length, 6);
			glVertex3f(-12, length, 6);
			glNormal3f(0, 0, -1);
			glVertex3f(12, -14, -6);
			glVertex3f(-12, -14, -6);
			glVertex3f(-12, length, -6);
			glVertex3f(12, length, -6);
			glNormal3f(0, -1, 0);
			glVertex3f(-12, -14, -6);
			glVertex3f(12, -14, -6);
			glVertex3f(12, -14, 6);
			glVertex3f(-12, -14, 6);
			glNormal3f(0, 1, 0);
			glVertex3f(12, length, -6);
			glVertex3f(-12, length, -6);
			glVertex3f(-12, length, 6);
			glVertex3f(12, length, 6);
			glNormal3f(-1, 0, 0);
			glVertex3f(-12, length, -6);
			glVertex3f(-12, -14, -6);
			glVertex3f(-12, -14, 6);
			glVertex3f(-12, length, 6);
			glNormal3f(1, 0, 0);
			glVertex3f(12, -14, -6);
			glVertex3f(12, length, -6);
			glVertex3f(12, length, 6);
			glVertex3f(12, -14, 6);
			glEnd();
			glPopMatrix();
			glDisable(GL_BLEND);
			glDisable(GL_LIGHTING);
		}
		if(machine[i].meshatekcount>0)
		{
			const dReal * pos0 = dBodyGetPosition(machine[i].body[0]);
			const dReal * pos1 = dBodyGetPosition(machine[i].body[1]);
			double length=sqrt(
					(pos0[0]-pos1[0])*(pos0[0]-pos1[0]) +
					(pos0[1]-pos1[1])*(pos0[1]-pos1[1]) +
					(pos0[2]-pos1[2])*(pos0[2]-pos1[2]))+3;
			glEnable(GL_BLEND);
			glEnable(GL_LIGHTING);
			glPushMatrix();
			position_gl(machine[i].body[0]);
			glColor4f(1, 1, 1, machine[i].meshatekcount>1?((machine[i].meshatekcount-(int)machine[i].meshatekcount)/6.0+0.2):machine[i].meshatekcount/2);
			glBegin(GL_QUADS);
			glNormal3f(0, 0, 1);
			glVertex3f(-12, -14, 6);
			glVertex3f(12, -14, 6);
			glVertex3f(12, length, 6);
			glVertex3f(-12, length, 6);
			glNormal3f(0, 0, -1);
			glVertex3f(12, -14, -6);
			glVertex3f(-12, -14, -6);
			glVertex3f(-12, length, -6);
			glVertex3f(12, length, -6);
			glNormal3f(0, -1, 0);
			glVertex3f(-12, -14, -6);
			glVertex3f(12, -14, -6);
			glVertex3f(12, -14, 6);
			glVertex3f(-12, -14, 6);
			glNormal3f(0, 1, 0);
			glVertex3f(12, length, -6);
			glVertex3f(-12, length, -6);
			glVertex3f(-12, length, 6);
			glVertex3f(12, length, 6);
			glNormal3f(-1, 0, 0);
			glVertex3f(-12, length, -6);
			glVertex3f(-12, -14, -6);
			glVertex3f(-12, -14, 6);
			glVertex3f(-12, length, 6);
			glNormal3f(1, 0, 0);
			glVertex3f(12, -14, -6);
			glVertex3f(12, length, -6);
			glVertex3f(12, length, 6);
			glVertex3f(12, -14, 6);
			glEnd();
			glPopMatrix();
			glDisable(GL_BLEND);
			glDisable(GL_LIGHTING);
		}
	}
	glDisable(GL_CULL_FACE);
	
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glEnable(GL_BLEND);
	glBindTexture(GL_TEXTURE_2D, poweruptex);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	glDepthMask(GL_FALSE);
	for(i=0; i<powerups.numpowerups; i++)
	{
		glPushMatrix();
		glTranslatef(powerups.getPowerup(i).x, powerups.getPowerup(i).y, 5);
		glRotatef(powerups.spin, 1, 0, 0);
		if(powerups.getPowerup(i).type==0)
			glColor3f(0.33, 0.33, 1);
		else if(powerups.getPowerup(i).type==1)
			glColor3f(0.33, 1, 0.33);
		else if(powerups.getPowerup(i).type==2)
			glColor3f(1, 0.33, 1);
		else if(powerups.getPowerup(i).type==3)
			glColor3f(1, 1, 0.33);
		else if(powerups.getPowerup(i).type==4)
			glColor3f(0.4, 0.4, 0.4);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex3f(-5, -5, 0);
		glTexCoord2f(1, 0);
		glVertex3f(5, -5, 0);
		glTexCoord2f(1, 1);
		glVertex3f(5, 5, 0);
		glTexCoord2f(0, 1);
		glVertex3f(-5, 5, 0);
		glEnd();
		glRotatef(90+powerups.spin*2, 0, 1, 0);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex3f(-5, -5, 0);
		glTexCoord2f(1, 0);
		glVertex3f(5, -5, 0);
		glTexCoord2f(1, 1);
		glVertex3f(5, 5, 0);
		glTexCoord2f(0, 1);
		glVertex3f(-5, 5, 0);
		glEnd();
		glRotatef(90+powerups.spin*4, 1, 0, 0);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex3f(-5, -5, 0);
		glTexCoord2f(1, 0);
		glVertex3f(5, -5, 0);
		glTexCoord2f(1, 1);
		glVertex3f(5, 5, 0);
		glTexCoord2f(0, 1);
		glVertex3f(-5, 5, 0);
		glEnd();
		glPopMatrix();
	}

	glBindTexture(GL_TEXTURE_2D, explosiontex);
	for(i=0; i<explosions.numexplosions; i++)
	{
		glPushMatrix();
		glTranslatef(explosions.getExplosion(i).x, explosions.getExplosion(i).y, explosions.getExplosion(i).z);
		glScalef(explosions.getExplosion(i).curradius*1.4, explosions.getExplosion(i).curradius*1.4, 1);
		glColor4f(1, 1, 1, 1.0-explosions.getExplosion(i).life/explosions.getExplosion(i).lifetime);
		glBegin(GL_QUADS);
		if(explosions.getExplosion(i).life/explosions.getExplosion(i).lifetime<=0.25)
		{
			glTexCoord2f(0, 0.5);
			glVertex3f(-1, -1, 0);
			glTexCoord2f(0.5, 0.5);
			glVertex3f(1, -1, 0);
			glTexCoord2f(0.5, 1);
			glVertex3f(1, 1, 0);
			glTexCoord2f(0, 1);
			glVertex3f(-1, 1, 0);
		}
		else if(explosions.getExplosion(i).life/explosions.getExplosion(i).lifetime<=0.5)
		{
			glTexCoord2f(0.5, 0.5);
			glVertex3f(-1, -1, 0);
			glTexCoord2f(1, 0.5);
			glVertex3f(1, -1, 0);
			glTexCoord2f(1, 1);
			glVertex3f(1, 1, 0);
			glTexCoord2f(0.5, 1);
			glVertex3f(-1, 1, 0);
		}
		else if(explosions.getExplosion(i).life/explosions.getExplosion(i).lifetime<=0.75)
		{
			glTexCoord2f(0, 0);
			glVertex3f(-1, -1, 0);
			glTexCoord2f(0.5, 0);
			glVertex3f(1, -1, 0);
			glTexCoord2f(0.5, 0.5);
			glVertex3f(1, 1, 0);
			glTexCoord2f(0, 0.5);
			glVertex3f(-1, 1, 0);
		}
		else
		{
			glTexCoord2f(0.5, 0);
			glVertex3f(-1, -1, 0);
			glTexCoord2f(1, 0);
			glVertex3f(1, -1, 0);
			glTexCoord2f(1, 0.5);
			glVertex3f(1, 1, 0);
			glTexCoord2f(0.5, 0.5);
			glVertex3f(-1, 1, 0);
		}
		glEnd();
		glPopMatrix();
	}
	
	glEnable(GL_DEPTH_TEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glBindTexture(GL_TEXTURE_2D, weaponstex);

	glColor3f(1, 1, 1);
	for(i=0; i<mines.nummines; i++)
	{
		glPushMatrix();
		if(mines.getMine(i).danger)
		{
			glTranslatef(mines.getMine(i).x, mines.getMine(i).y, 6);
			glBegin(GL_QUADS);
			glTexCoord2f(0.5, 0);
			glVertex3f(-3, -3, 0);
			glTexCoord2f(1, 0);
			glVertex3f(3, -3, 0);
			glTexCoord2f(1, 0.5);
			glVertex3f(3, 3, 0);
			glTexCoord2f(0.5, 0.5);
			glVertex3f(-3, 3, 0);
			glEnd();
		}
		else
		{
			glTranslatef(mines.getMine(i).x, mines.getMine(i).y, 3);
			glBegin(GL_QUADS);
			glTexCoord2f(0, 0);
			glVertex3f(-3, -3, 0);
			glTexCoord2f(0.5, 0);
			glVertex3f(3, -3, 0);
			glTexCoord2f(0.5, 0.5);
			glVertex3f(3, 3, 0);
			glTexCoord2f(0, 0.5);
			glVertex3f(-3, 3, 0);
			glEnd();
		}
		glPopMatrix();
	}

	glDepthMask(GL_TRUE);

	for(i=0; i<projectiles.numprojectiles; i++)
	{
		glPushMatrix();
		glTranslatef(projectiles.getProjectile(i).x, projectiles.getProjectile(i).y, 6);
		glRotatef(projectiles.getProjectile(i).angle, 0, 0, -1);
		glDisable(GL_TEXTURE_2D);
		glBegin(GL_QUADS);
		glColor4f(1, 0, 0, 0.7);
		glVertex3f(1, 0, 0);
		glVertex3f(-1, 0, 0);
		glColor4f(1, 1, 0, 0);
		glVertex3f(-0.5, -projectiles.getProjectile(i).length, 0);
		glVertex3f(0.5, -projectiles.getProjectile(i).length, 0);
		glEnd();
		glEnable(GL_TEXTURE_2D);
		glColor3f(1, 1, 1);
		glBegin(GL_QUADS);
		if(projectiles.getProjectile(i).type==0)
		{
			glTexCoord2f(0, 0.5);
			glVertex3f(-5, -5, 0);
			glTexCoord2f(0.5, 0.5);
			glVertex3f(5, -5, 0);
			glTexCoord2f(0.5, 1);
			glVertex3f(5, 5, 0);
			glTexCoord2f(0, 1);
			glVertex3f(-5, 5, 0);
		}
		else
		{
			glTexCoord2f(0.5, 0.5);
			glVertex3f(-5, -5, 0);
			glTexCoord2f(1, 0.5);
			glVertex3f(5, -5, 0);
			glTexCoord2f(1, 1);
			glVertex3f(5, 5, 0);
			glTexCoord2f(0.5, 1);
			glVertex3f(-5, 5, 0);
		}
		glEnd();
		glPopMatrix();
	}

		
	glDisable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);

	glDisable(GL_DEPTH_TEST);

	if(options.logoshow)
	{
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(0, 800, 0, 600, -1, 1);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glBindTexture(GL_TEXTURE_2D, bennykramekwebtex);
		glColor4f(1, 1, 1, 0.7);
		glEnable(GL_BLEND);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex2i(544, 0);
		glTexCoord2f(1, 0);
		glVertex2i(800, 0);
		glTexCoord2f(1, 1);
		glVertex2i(800, 32);
		glTexCoord2f(0, 1);
		glVertex2i(544, 32);
		glEnd();
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
	}

	if(goalcount>0)
	{
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(0, 800, 0, 600, -1, 1);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glColor4f(0.8, 1, 0.8, goalcount/6.0);
		glBegin(GL_QUADS);
		glVertex2i(0, 0);
		glVertex2i(800, 0);
		glVertex2i(800, 600);
		glVertex2i(0, 600);
		glEnd();
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, goaltex);
		glColor4f(1, 1, 1, goalcount/4.0);
		glTranslatef(400, 300, 0);
		glScalef(1-goalcount/4.0, 1-goalcount/4.0, 0);
		glRotatef(goalcount/4.0*360+180, 0, 0, 1);
		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex2i(-400, -300);
		glTexCoord2f(1, 0);
		glVertex2i(400, -300);
		glTexCoord2f(1, 1);
		glVertex2i(400, 300);
		glTexCoord2f(0, 1);
		glVertex2i(-400, 300);
		glEnd();
		glDisable(GL_TEXTURE_2D);
		glEnable(GL_DEPTH_TEST);
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
	}

	if(gameover)
	{
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(0, 800, 0, 600, -1, 1);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glColor4f(0, 0, 0, 0.6);
		glBegin(GL_QUADS);
		glVertex2i(100, 100);
		glVertex2i(700, 100);
		glVertex2i(700, 500);
		glVertex2i(100, 500);
		glEnd();
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
	}

	if(gamepaused)
	{
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho(0, 800, 0, 600, -1, 1);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glColor4f(0, 0, 0, 0.6);
		glBegin(GL_QUADS);
		glVertex2i(100, 100);
		glVertex2i(700, 100);
		glVertex2i(700, 500);
		glVertex2i(100, 500);
		glEnd();
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
	}

	
	text.begin();
	char a[10];
	if(options.fpsshow)
	{
		glColor3f(0.3, 0.3, 0.3);
		sprintf(a, "%2.0f", 1.0/(m*4));
		text.print(0, 0, a);
	}
	if(rendertime && gametime>=0)
	{
		sprintf(a, "%2.2d:%2.2d:%2.2d", (int)(gametime/60), (int)(gametime)%60, (int)((gametime-(int)(gametime))*100));
		glColor3f(0, 0, 0);
		text.print(332, 558, a);
		glColor3f(1, 1, 1);
		if(gametime<=10)
			glColor3f(1, 0, 0);
		text.print(330, 560, a);
	}
	if(rendertime && gametime<0)
	{
		sprintf(a, "%2.2d:%2.2d:%2.2d", 0, 0, 0);
		glColor3f(0, 0, 0);
		text.print(332, 558, a);
		glColor3f(1, 1, 1);
		glColor3f(1, 0, 0);
		text.print(330, 560, a);
	}
	glColor3f(0, 0, 0);
	sprintf(a, "%d", (int)goals[0]);
	text.print(102, 558, a);
	glColor3f(0, 0, 1);
	text.print(100, 560, a);
	glColor3f(0, 0, 0);
	sprintf(a, "%d", (int)goals[1]);
	text.print(682, 558, a);
	glColor3f(0, 0, 1);
	text.print(680, 560, a);
	if(gameover)
	{
		glColor3f(1, 1, 1);
		text.print(290, 400, "GAME OVER");
		if(goals[0]>goals[1])
		{
			glColor3f(1, 0.6, 0.4);
			text.print(240, 280, "PLAYER 1 WINS!");
			glColor3f(1, 1, 1);
			text.print(200, 240, "PLAYER 2: YOU SUCK!");
		}
		if(goals[1]>goals[0])
		{
			glColor3f(1, 1, 1);
			text.print(240, 280, "PLAYER 2 WINS!");
			glColor3f(1, 0.6, 0.4);
			text.print(200, 240, "PLAYER 1: YOU SUCK!");
		}
		if(goals[0]==goals[1])
		{
			text.print(300, 280, "TIE GAME!");
			text.print(240, 240, "YOU BOTH SUCK!");
		}
		glColor3f(1, 1, 1);
		text.print(250, 140, "PRESS ESCAPE");
	}
	if(gamepaused)
	{
		glColor3f(1, 0, 0);
		text.print(340, 400, "PAUSE");

		glColor3f(1, 1, 1);
		text.print(120, 340, "CURRENT SONG:");
		text.print(105, 280, "<");
		text.print(680, 280, ">");
		int mama_of;
		for(mama_of=0; mama_of<12; mama_of++)
		{
			char turd[3];
			sprintf(turd, "%d", mama_of+1);
			if(mama_of==currentsong)
				glColor3f(1, 1, 0);
			else
				glColor3f(0.6, 0.6, 1);
			text.print(135+mama_of*45, 280, turd);
		}
					

		glColor3f(1, 1, 1);
		text.print(120, 160, "PRESS ESCAPE TO RESUME");
		text.print(200, 120, "PRESS F11 TO QUIT");
	}
	text.end();
	glEnable(GL_LIGHTING);
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);

	glFlush();
	allegro_gl_flip();
	allegro_gl_end();
}
コード例 #11
0
ファイル: lathe.c プロジェクト: AntonLanghoff/whitecatlib
int main()
{
    /* Setup Allegro/AllegroGL */

	if (allegro_init())
		return 1;

	if (install_allegro_gl())
		return 1;

    if (install_keyboard() < 0)
    {
        allegro_message("Unable to install keyboard\n");
        return 1;
    }

    if (install_mouse() == -1)
    {
        allegro_message("Unable to install mouse\n");
        return 1;
    }

    if (install_timer() < 0)
    {
        allegro_message("Unable to install timers\n");
        return 1;
    }

    /* lock timer */
    LOCK_VARIABLE(rotation_counter);
    LOCK_FUNCTION(rotation_counter_handler);


    /* set desktop resolution */
    DESKTOP_W = GetSystemMetrics(SM_CXVIRTUALSCREEN);
    DESKTOP_H = GetSystemMetrics(SM_CYVIRTUALSCREEN);

    /* get monitor resolution/count */
    int monitor_count;
    MONITOR *monitors = get_monitors(&monitor_count);


    /* generate point data */
    PLACE places[POINT_COUNT];
    int c;
    for (c = 1; c < POINT_COUNT - 1; c++)
    {
        places[c].x = sin((M_PI * (GLfloat)c) / 10.0f) * 200.0f;
        places[c].y = cos((M_PI * (GLfloat)c) / 10.0f) * 200.0f;
    }
    places[0].x = 0.01;
    places[0].y = 200.0f;
    places[POINT_COUNT - 1].x = 0.01;
    places[POINT_COUNT - 1].y = -200.0f;


    /* setup display */
    allegro_gl_set(AGL_Z_DEPTH, 8);
	allegro_gl_set(AGL_COLOR_DEPTH, 16);
	allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH);
    glDepthFunc(GL_LEQUAL);

	if (set_gfx_mode(GFX_OPENGL_WINDOWED_BORDERLESS, DESKTOP_W, DESKTOP_H, 0, 0)) {
		set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
		allegro_message("Unable to set graphic mode\n%s\n", allegro_error);
		return 1;
	}

    /* move window so it covers the desktop */
    position_window(0, 0);


    /* fake information to use if only 1 monitor */
    MONITOR fake = {0, 512, 512, 512};

    /* setup lighting model */
    glShadeModel(GL_FLAT);
    glEnable(GL_LIGHT0);
    glEnable(GL_COLOR_MATERIAL);
    GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    GLfloat ambient[] = { 0.1f, 0.1f, 0.1f };
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);


    int selected = -1; /* the point currently being moved */
    GLfloat rotation[3] = {0, 0, 0}; /* the rotation of the mesh */

    install_int(rotation_counter_handler, 20); /* install the rotation handler */

    /* enter main program loop */
    while(!key[KEY_ESC])
    {
        while (rotation_counter > 0)
        {
            /* rotate the mesh */
            rotation[0] += M_PI / 24.0f;
            rotation[1] += M_PI / 16.0f;
            rotation[2] += M_PI /  8.0f;
            rotation_counter--;
        }


        /* clear the buffers */
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        /* process monitor 0 */
        MONITOR *m = &monitors[0];

        /* adjust mouse so its relative to the monitor */
        int mx = (mouse_x - m->x) - (m->w / 2);
        int my = (mouse_y - m->y) - (m->h / 2);

        /* if the left mouse is pushed, find a close point */
        if (mouse_b & 1)
        {
            if (selected == -1)
            {
                GLfloat distance = 10;
                for (c = 0; c < POINT_COUNT; c++)
                {
                    GLfloat dx = mx - places[c].x;
                    GLfloat dy = my - places[c].y;
                    GLfloat d = sqrt(dx * dx + dy * dy);
                    if (d < distance)
                    {
                        distance = d;
                        selected = c;
                    }
                }
            }
        }
        else
            selected = -1;

        /* move selected point */
        if (selected >= 0)
        {
            places[selected].x = mx;
            places[selected].y = my;
        }

        /* center the viewport on monitor */
        glViewport(m->x, DESKTOP_H - m->h - m->y, m->w, m->h);

        /* setup viewport projection */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(-m->w / 2, m->w / 2, m->h / 2, -m->h / 2);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        /* draw points */
        glColor3ub(0, 255, 0);
        glBegin(GL_LINE_STRIP);
        for (c = 0; c < POINT_COUNT; c++)
        {
            glVertex2f(places[c].x, places[c].y);
        }
        glEnd();

        glColor3ub(255, 255, 255);
        for (c = 0; c < POINT_COUNT; c++)
        {
            draw_square(places[c].x, places[c].y, 10);
        }

        /* draw vertical line */
        glBegin(GL_LINE_STRIP);
        glVertex2f(0.0f, -m->h);
        glVertex2f(0.0f, m->h);
        glEnd();


        /* draw the mouse */
        glColor3ub(255, 255, 255);
        draw_square(mx, my, 20);



        /* process viewport 1 */

        /* select second monitor */
        if (monitor_count > 1)
        {
            /* if 2nd monitor exists use it */
            m = &monitors[1];
        }
        else
        {
            /* use fake monitor */
            m = &fake;
        }

        /* adjust mouse so its relative to the monitor*/
        mx = (mouse_x - m->x) - (m->w / 2);
        my = (mouse_y - m->y) - (m->h / 2);

        /* center the viewport on the monitor*/
        glViewport(m->x, DESKTOP_H - m->h - m->y, m->w, m->h);

        /* setup viewport projection */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, (float)m->w / (float)m->h, 0.1f, 2000.0f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        /* turn on lighting and depth testing */
        glEnable(GL_LIGHTING);
        glEnable(GL_DEPTH_TEST);

        /* move mesh so its visible */
        glTranslatef(0.0f, 0.0f, -1000.0f);
        /* rotate mesh */
        glRotatef(rotation[0], 1.0f, 0.0f, 0.0f);
        glRotatef(rotation[1], 0.0f, 1.0f, 0.0f);
        glRotatef(rotation[2], 0.0f, 0.0f, 1.0f);

        GLfloat p1[3] = {0, 0, 0};
        GLfloat p2[3] = {0, 0, 0};
        GLfloat p3[3] = {0, 0, 0};
        GLfloat p4[3] = {0, 0, 0};
        GLfloat vec1[3];
        GLfloat vec2[3];
        GLfloat normal[3];


        /* draw mesh to screen */
        glColor3ub(0, 255, 0);
        for (c = 0; c < (POINT_COUNT - 1); c++)
        {

            GLfloat a1 = 0;
            GLfloat a2 = M_PI / 16.0f;
            GLfloat d1 = places[c].x;
            GLfloat d2 = places[c + 1].x;

            p1[0] = sin(a1) * d1;  p1[1] = places[c].y;     p1[2] = cos(a1) * d1;
            p2[0] = sin(a2) * d1;  p2[1] = places[c].y;     p2[2] = cos(a2) * d1;
            p3[0] = sin(a2) * d2;  p3[1] = places[c + 1].y; p3[2] = cos(a2) * d2;
            p4[0] = sin(a1) * d2;  p4[1] = places[c + 1].y; p4[2] = cos(a1) * d2;

            buildVector(vec1, p1, p2);
            buildVector(vec2, p1, p4);
            cross_product_f(vec2[0], vec2[1], vec2[2], vec1[0], vec1[1], vec1[2], &normal[0], &normal[1], &normal[2]);
            normalize_vector_f(&normal[0], &normal[1], &normal[2]);


            glBegin(GL_QUAD_STRIP);
            glNormal3fv(normal);
            glVertex3fv(p1);
            glVertex3fv(p4);

            int s = 0;
            for (s = 1; s < 32; s++)
            {
                a2 = (M_PI * (GLfloat)(s + 1)) / 16.0f;
                d1 = places[c].x;
                d2 = places[c + 1].x;

                copyPoint(p1, p2);
                copyPoint(p4, p3);
                p2[0] = sin(a2) * d1;  p2[1] = places[c].y;     p2[2] = cos(a2) * d1;
                p3[0] = sin(a2) * d2;  p3[1] = places[c + 1].y; p3[2] = cos(a2) * d2;

                buildVector(vec1, p1, p2);
                buildVector(vec2, p1, p4);
                cross_product_f(vec2[0], vec2[1], vec2[2], vec1[0], vec1[1], vec1[2], &normal[0], &normal[1], &normal[2]);
                normalize_vector_f(&normal[0], &normal[1], &normal[2]);

                glNormal3fv(normal);
                glVertex3fv(p2);
                glVertex3fv(p3);
            }
            glEnd();
        }

        /* turn off lighting and depth testing */
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);

        /* if not using the fake monitor */
        if (m != &fake)
        {

            /* setup viewport projection */
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            gluOrtho2D(-m->w / 2, m->w / 2, m->h / 2, -m->h / 2);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();

            /* draw the mouse */
            glColor3ub(255, 255, 255);
            draw_square(mx, my, 20);
        }

        /* flip the contents to the screen */
        allegro_gl_flip();
    }


    free(monitors);

    return 0;
}