Beispiel #1
0
void draw_3d_object_detail(object3d * object_id, Uint32 material_index, Uint32 use_lightning,
	Uint32 use_textures, Uint32 use_extra_textures)
{
	e3d_vertex_data* vertex_layout;
	Uint8 * data_ptr;

	// check for having to load the arrays
	load_e3d_detail_if_needed(object_id->e3d_data);

	CHECK_GL_ERRORS();
	//also, update the last time this object was used
	object_id->last_acessed_time = cur_time;

	//debug

	if (object_id->self_lit && (!is_day || dungeon) && use_lightning) 
	{
		glColor3fv(object_id->color);
	}

	CHECK_GL_ERRORS();

	glPushMatrix();//we don't want to affect the rest of the scene

	glMultMatrixf(object_id->matrix);

	CHECK_GL_ERRORS();

	if (!dungeon && (clouds_shadows || use_shadow_mapping) && use_extra_textures)
	{
		VECTOR4 plane;

		ELglActiveTextureARB(detail_unit);
		memcpy(plane, object_id->clouds_planes[0], sizeof(VECTOR4));
		plane[3] += clouds_movement_u;
		glTexGenfv(GL_S, GL_EYE_PLANE, plane);
		memcpy(plane, object_id->clouds_planes[1], sizeof(VECTOR4));
		plane[3] += clouds_movement_v;
		glTexGenfv(GL_T, GL_EYE_PLANE, plane);
		ELglActiveTextureARB(base_unit);
	}

	// watch for a change
	if (object_id->e3d_data != cur_e3d)
	{
		if ((cur_e3d != NULL) && (use_compiled_vertex_array))
		{
			ELglUnlockArraysEXT();
		}

		if (use_vertex_buffers)
		{
			ELglBindBufferARB(GL_ARRAY_BUFFER_ARB,
				object_id->e3d_data->vertex_vbo);
			data_ptr = 0;
		}
		else
		{
			data_ptr = object_id->e3d_data->vertex_data;
		}

		vertex_layout = object_id->e3d_data->vertex_layout;

		if ((vertex_layout->normal_count > 0) && use_lightning)
		{
			glEnableClientState(GL_NORMAL_ARRAY);
			glNormalPointer(vertex_layout->normal_type, vertex_layout->size,
				data_ptr + vertex_layout->normal_offset);
		}
		else
		{
			glDisableClientState(GL_NORMAL_ARRAY);
			glNormal3f(0.0f, 0.0f, 1.0f);
		}

		if (use_textures)
		{
			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
			glTexCoordPointer(vertex_layout->texture_count, vertex_layout->texture_type,
				vertex_layout->size, data_ptr + vertex_layout->texture_offset);
		}
		else
		{
			glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		}

		glVertexPointer(vertex_layout->position_count, vertex_layout->position_type,
			vertex_layout->size, data_ptr + vertex_layout->position_offset);

		if (use_vertex_buffers)
		{
			ELglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
				object_id->e3d_data->indices_vbo);
		}

		// lock this new one
		if (use_compiled_vertex_array)
		{
			ELglLockArraysEXT(0, object_id->e3d_data->vertex_no);
		}
		// gather statistics
		if (object_id->e3d_data != cur_e3d)
		{
#ifdef  DEBUG
			if ((cur_e3d_count > 0) && (cur_e3d != NULL))
			{
				e3d_count++;
				e3d_total += cur_e3d_count;
			}
			cur_e3d_count = 0;
#endif    //DEBUG
			cur_e3d = object_id->e3d_data;
		}
	}
#ifdef  DEBUG
	cur_e3d_count++;
#endif  //DEBUG

	if (use_textures)
	{
		glEnable(GL_TEXTURE_2D);
#ifdef	NEW_TEXTURES
		bind_texture(object_id->e3d_data->materials[material_index].texture);
#else	/* NEW_TEXTURES */
		get_and_set_texture_id(object_id->e3d_data->materials[material_index].texture);
#endif	/* NEW_TEXTURES */
	}
	else
	{
		glDisable(GL_TEXTURE_2D);		
	}


	if (use_draw_range_elements && ELglDrawRangeElementsEXT)
		ELglDrawRangeElementsEXT(GL_TRIANGLES,
			object_id->e3d_data->materials[material_index].triangles_indices_min,
			object_id->e3d_data->materials[material_index].triangles_indices_max,
			object_id->e3d_data->materials[material_index].triangles_indices_count,
			object_id->e3d_data->index_type,
			object_id->e3d_data->materials[material_index].triangles_indices_index);
	else
		glDrawElements(GL_TRIANGLES,
			object_id->e3d_data->materials[material_index].triangles_indices_count,
			object_id->e3d_data->index_type,
			object_id->e3d_data->materials[material_index].triangles_indices_index);

	glPopMatrix();//restore the scene
	CHECK_GL_ERRORS();

	//OK, let's check if our mouse is over...
#ifdef MAP_EDITOR2
	if (selected_3d_object == -1 && read_mouse_now && mouse_in_sphere(object_id->x_pos, object_id->y_pos, object_id->z_pos, object_id->e3d_data->radius))
		anything_under_the_mouse(object_id->id, UNDER_MOUSE_3D_OBJ);
#endif
}
Beispiel #2
0
/* Draw a single character at the given position and brightness.
 */
static void
draw_glyph (ModeInfo *mi, int glyph, Bool highlight,
            GLfloat x, GLfloat y, GLfloat z,
            GLfloat brightness)
{
  matrix_configuration *mp = &mps[MI_SCREEN(mi)];
  int wire = MI_IS_WIREFRAME(mi);
  GLfloat w = mp->tex_char_width;
  GLfloat h = mp->tex_char_height;
  GLfloat cx = 0, cy = 0;
  GLfloat S = 1;
  Bool spinner_p = (glyph < 0);

  if (glyph == 0) abort();
  if (glyph < 0) glyph = -glyph;

  if (spinner_p)
    brightness *= 1.5;

  if (!do_texture)
    {
      S  = 0.8;
      x += 0.1;
      y += 0.1;
    }
  else
    {
      int ccx = ((glyph - 1) % CHAR_COLS);
      int ccy = ((glyph - 1) / CHAR_COLS);

      cx = ccx * w;
      cy = (mp->real_char_rows - ccy - 1) * h;

      if (do_fog)
        {
          GLfloat depth;
          depth = (z / GRID_DEPTH) + 0.5;  /* z ratio from back/front      */
          depth = 0.2 + (depth * 0.8);     /* scale to range [0.2 - 1.0]   */
          brightness *= depth;             /* so no row goes all black.    */
        }
    }

  {
    GLfloat r, g, b, a;

    if (highlight)
      brightness *= 2;

    if (!do_texture && !spinner_p)
      r = b = 0, g = 1;
    else
      r = g = b = 1;

    a = brightness;

    /* If the glyph is very close to the screen (meaning it is very large,
       and is about to splash into the screen and vanish) then start fading
       it out, proportional to how close to the glass it is.
    */
    if (z > GRID_DEPTH/2)
      {
        GLfloat ratio = ((z - GRID_DEPTH/2) /
                         ((GRID_DEPTH * SPLASH_RATIO) - GRID_DEPTH/2));
        int i = ratio * WAVE_SIZE;

        if (i < 0) i = 0;
        else if (i >= WAVE_SIZE) i = WAVE_SIZE-1; 

        a *= mp->brightness_ramp[i];
      }

    glColor4f (r,g,b,a);
  }

  glBegin (wire ? GL_LINE_LOOP : GL_QUADS);
  glNormal3f (0, 0, 1);
  glTexCoord2f (cx,   cy);   glVertex3f (x,   y,   z);
  glTexCoord2f (cx+w, cy);   glVertex3f (x+S, y,   z);
  glTexCoord2f (cx+w, cy+h); glVertex3f (x+S, y+S, z);
  glTexCoord2f (cx,   cy+h); glVertex3f (x,   y+S, z);
  glEnd ();

  if (wire && spinner_p)
    {
      glBegin (GL_LINES);
      glVertex3f (x,   y,   z);
      glVertex3f (x+S, y+S, z);
      glVertex3f (x,   y+S, z);
      glVertex3f (x+S, y,   z);
      glEnd();
    }

  mi->polygon_count++;
}
 static void ArchFaceVault(float xValue, float resize) {
	 glPushMatrix();
	int i, numSlices;
	glTranslatef(xValue, 0, 0);
	glScalef(resize, 1, 1);
   double angle;
   double angInc;
   numSlices = 20;
   angle = 0;
   angInc = 3.14159/(2 * numSlices);

   for (i = 0; i < numSlices; i++) {

	   glNormal3f(0,0,1);
	      glColor3f(1,0,0);
       glBegin(GL_POLYGON);
       glVertex3f(1,0,1);  // corner
       glVertex3f( cos(angle) , sin(angle)-1, 1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, 1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(-1,0,1);  // corner
       glVertex3f(- cos(angle) , sin(angle)-1, 1);
       glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, 1);
       glEnd();

	   //---
	   glNormal3f(0,0,-1);
       glBegin(GL_POLYGON);
       glVertex3f(1,0,-1);  // corner
       glVertex3f( cos(angle) , sin(angle)-1, -1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(-1,0,-1);  // corner
       glVertex3f(- cos(angle) , sin(angle)-1, -1);
       glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

	   // vault

	   glNormal3f(-cos(angle+angInc/2),-sin(angle+angInc/2),0);


	   glColor3f(0,0,1);
       glBegin(GL_POLYGON);
       glVertex3f(  cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( cos(angle) ,       sin(angle)-1, -1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(  cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( cos(angle+angInc) ,       sin(angle+angInc)-1, 1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

	   glNormal3f(cos(angle+angInc/2),-sin(angle+angInc/2),0);

       glBegin(GL_POLYGON);
       glVertex3f( - cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( -cos(angle) ,       sin(angle)-1, -1);
       glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f( - cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( -cos(angle+angInc) ,       sin(angle+angInc)-1, 1);
       glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();



	   angle += angInc;
   
   }
   glPopMatrix();
}
void SCENE::SetupDummies()
{
	bool Lighting=true;
	//na ez lovi be a scene display listjeit

	ObjDummyCount=CountObjects();
	ObjDummies=new OBJDUMMY[ObjDummyCount];
	memset(ObjDummies,0,sizeof(OBJDUMMY)*ObjDummyCount); //dummy tomb

	int FilledDummy=0;

	int x;
	for (x=0; x<ObjectNum; x++) //dummy tomb feltoltese
	{
		if (ObjectList[x].Primitive<100 && ObjectList[x].Primitive!=11 /*clone*/) CalculateDummy(&ObjectList[x],FilledDummy,&ObjectList[x].ModelView);
		if (ObjectList[x].Primitive==11 /*clone*/) SetupClones(this,x,FilledDummy,&ObjectList[x].ModelView);
	}

	qsort(ObjDummies,ObjDummyCount,sizeof(OBJDUMMY),DummyCompare); //attributumsort

	glNewList(ZmaskList,GL_COMPILE); //ket lista keszul, egy a zmaskos objecteknek, egy a nem zmaskosoknak
									 //ez a zmaskos, a nem zmaskos a valtaskor kap erteket
	glBegin(GL_TRIANGLES);
	unsigned char c[4],o[4];
	for (x=0; x<4; x++) c[x]=o[x]=2;

	for (int z=0; z<ObjDummyCount; z++) //a fo loop
	{
		//glErrorCheck();
		OBJECT *LastObject=NULL;
		if (z) LastObject=ObjDummies[z-1].OriginalObj;  //ez az elozo object, referencianak h melyik
														//attributum valtozott


		OBJECT *Object=ObjDummies[z].OriginalObj;		//az aktualis object

		//MATRIX Position;
		//memcpy(&Position,ObjDummies[z].ModelView,sizeof(MATRIX)); //az object pozicioja
		/*MATRIX InvTransp;
		memcpy(&InvTransp,&Position,sizeof(MATRIX));
		M_Invert(InvTransp);
		M_Transpose(InvTransp);*/
		
		//eltranszformaljuk az osszes vertexet a vegleges pozicioba, es kiszamoljuk a normalokat,
		//erre azert van szukseg mert igy jok lesznek a normalok es a nonuniform scalezettek nem bugzanak be
		for (x=0; x<Object->VertexNum; x++)
		{
				Object->VertexList[x].MapTransformedPosition=Object->VertexList[x].Position;
				M_Xformd(ObjDummies[z].ModelView,Object->VertexList[x].MapTransformedPosition,Object->VertexList[x].MapTransformedPosition);
		}
		Object->CalculateNormals();

		//ha szinvaltozas van
		bool NewCol=!LastObject;
		if (!ColorDiscard && LastObject) for (int a=0; a<4; a++) if (Object->Color.c[a]!=LastObject->Color.c[a]) NewCol=true;

		bool Cut;

		//ha elertunk a zmask valtashoz
		bool ZmaskChange=!Object->ZMask && (!LastObject || LastObject->ZMask);
		NewCol=ZmaskChange || NewCol;
		//ha envmap objecthez ertunk
		bool EnvmapTurnOn=((LastObject && !ObjDummies[z-1].Envmap) || !LastObject) && ObjDummies[z].Envmap;
		//ha wireframe valtas van
		//bool WireframeChange=!LastObject || ZmaskChange || EnvmapTurnOn || (Object->Wireframe != LastObject->Wireframe);
		//ha kikapcsolodott a textura
		bool TextureDisable=(!Object->Textured && ((LastObject && LastObject->Textured) || !LastObject));// || (WireframeChange && Object->Wireframe && !ObjDummies[z].Envmap);
		//ha valtozott a textura
		bool TextureChange=Object->Textured && (ZmaskChange || (!LastObject || !LastObject->Textured) || (LastObject && LastObject->Material->TextureID*8+LastObject->Material->SlotNumber!=Object->Material->TextureID*8+Object->Material->SlotNumber));// || (WireframeChange && !Object->Wireframe && Object->Textured));
		//ha valtozott a blendmode
		bool BlendChange=!LastObject || LastObject->SRCBlend!=Object->SRCBlend || LastObject->DSTBlend!=Object->DSTBlend;
		//ha valtozott az envmap
		bool EnvmapChange=Object->EnvMap && LastObject && ObjDummies[z-1].Envmap && (LastObject->EnvMap->TextureID*8+LastObject->EnvMap->SlotNumber!=Object->EnvMap->TextureID*8+Object->EnvMap->SlotNumber);
		//ha valtozott a backface culling ki be kapcsoltsaga
		bool BackChange=!LastObject || ZmaskChange || (Object->Backface != LastObject->Backface);
		//ha valtozott a backface culling iranya
		bool BackFrontChange=!LastObject || ZmaskChange || (Object->Backface && Object->Backfront!=LastObject->Backfront);
		//ha valtozott az alpha epsilon
		bool AepsilonChange=!LastObject || ZmaskChange || (Object->AEpsilon != LastObject->AEpsilon);

		//ha meg kell szakitani modvaltas miatt a glbegin() glend()-et
		Cut=ZmaskChange || 
			(!ObjDummies[z].Envmap && (TextureDisable || TextureChange || BlendChange) ) ||
			(ObjDummies[z].Envmap && (EnvmapTurnOn || EnvmapChange)) ||
			(NewCol && !ColorDiscard) ||
			BackChange ||
			BackFrontChange ||
			AepsilonChange;
			//||WireframeChange;

		//ha meg kell szakitani, akkor megszakitjuk :)
		if (Cut) glEnd();

		//zmask valtas, innen a nem zmaskos objectek jonnek (kulon listaba mert egy world tobb scenebol
		//allhat, es eloszor a zmaskos scene listakat kell renderelni, utana a nem zmaskosakat)
		if (ZmaskChange)
		{
			glEndList();
			glNewList(NoZmaskList,GL_COMPILE);
		}

		//alpha epsilon valtas
		if (AepsilonChange)
		{
			glAlphaFunc(GL_GEQUAL,Object->AEpsilon/255.0f);
		}

		//szinvaltas
		if (!ColorDiscard && NewCol) glColor4ub(Object->Color.c[0],Object->Color.c[1],Object->Color.c[2],Object->Color.c[3]);

		//backface cull ki/bekapcs
		if (BackChange)
			if (Object->Backface) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE);
		//backface cull reverse
		if (BackFrontChange)
			if (Object->Backfront) glCullFace(GL_FRONT); else glCullFace(GL_BACK);


		//ha nem envmap az object
		if (!ObjDummies[z].Envmap)
		{
			//textura kikapcs
			if (TextureDisable) glDisable(GL_TEXTURE_2D);

			//texturavaltas
			if (TextureChange)
			{
				glEnable(GL_TEXTURE_2D);
				glBindTexture(GL_TEXTURE_2D,Object->Material->ImageData.TextureHandle);
			}
			//blendmodevaltas
			if (BlendChange) glBlendFunc(Object->DSTBlend,Object->SRCBlend);
		}
		else
		//ha envmap az object
		{
			//envmap bekapcs
			if (EnvmapTurnOn)
			{
				glEnable(GL_TEXTURE_2D);
				glBindTexture(GL_TEXTURE_2D,Object->EnvMap->ImageData.TextureHandle);
				glEnable(GL_TEXTURE_GEN_S);
				glEnable(GL_TEXTURE_GEN_T);
				glBlendFunc(GL_ONE,GL_ONE);
			}
			//envmap textura valtas
			if (EnvmapChange) glBindTexture(GL_TEXTURE_2D,Object->EnvMap->ImageData.TextureHandle);				
		}

		/*if (WireframeChange)
		{
			if (!Object->Wireframe || ObjDummies[z].Envmap) 
			{
				if (Lighting)
				glEnable(GL_LIGHTING);
			}
			else 
			{
				Lighting=glIsEnabled(GL_LIGHTING)!=0;
				glDisable(GL_LIGHTING);
			}
		}*/

		//ha vagas volt, ujra kell glbegin
		if (Cut) 
			if (!Object->Wireframe || ObjDummies[z].Envmap)
			glBegin(GL_TRIANGLES);
			else
			glBegin(GL_LINES);

		if (!Object->Wireframe || ObjDummies[z].Envmap)
		{
			for (x=0; x<Object->PolygonNum; x++)
			{
				if (Object->PolygonList[x].CurrentShading!=aDDict_GOURAUDSHADE) 
					glNormal3f(Object->PolygonList[x].CurrentNormal.x,Object->PolygonList[x].CurrentNormal.y,Object->PolygonList[x].CurrentNormal.z);
				
				//vertex1

				if (Object->PolygonList[x].CurrentShading==aDDict_GOURAUDSHADE) 
					glNormal3f(Object->VertexList[Object->PolygonList[x].v[0]].CurrentNormal.x,Object->VertexList[Object->PolygonList[x].v[0]].CurrentNormal.y,Object->VertexList[Object->PolygonList[x].v[0]].CurrentNormal.z);
				if (Object->Textured) glTexCoord2f(Object->PolygonList[x].ct[0].x,Object->PolygonList[x].ct[0].y);
				glVertex3f(Object->VertexList[Object->PolygonList[x].v[0]].MapTransformedPosition.x,Object->VertexList[Object->PolygonList[x].v[0]].MapTransformedPosition.y,Object->VertexList[Object->PolygonList[x].v[0]].MapTransformedPosition.z);

				//vertex2
				
				if (Object->PolygonList[x].CurrentShading==aDDict_GOURAUDSHADE) 
					glNormal3f(Object->VertexList[Object->PolygonList[x].v[1]].CurrentNormal.x,Object->VertexList[Object->PolygonList[x].v[1]].CurrentNormal.y,Object->VertexList[Object->PolygonList[x].v[1]].CurrentNormal.z);
				if (Object->Textured) glTexCoord2f(Object->PolygonList[x].ct[1].x,Object->PolygonList[x].ct[1].y);			
				glVertex3f(Object->VertexList[Object->PolygonList[x].v[1]].MapTransformedPosition.x,Object->VertexList[Object->PolygonList[x].v[1]].MapTransformedPosition.y,Object->VertexList[Object->PolygonList[x].v[1]].MapTransformedPosition.z);

				//vertex3
				
				if (Object->PolygonList[x].CurrentShading==aDDict_GOURAUDSHADE) 
					glNormal3f(Object->VertexList[Object->PolygonList[x].v[2]].CurrentNormal.x,Object->VertexList[Object->PolygonList[x].v[2]].CurrentNormal.y,Object->VertexList[Object->PolygonList[x].v[2]].CurrentNormal.z);
				if (Object->Textured) glTexCoord2f(Object->PolygonList[x].ct[2].x,Object->PolygonList[x].ct[2].y);
				glVertex3f(Object->VertexList[Object->PolygonList[x].v[2]].MapTransformedPosition.x,Object->VertexList[Object->PolygonList[x].v[2]].MapTransformedPosition.y,Object->VertexList[Object->PolygonList[x].v[2]].MapTransformedPosition.z);
			}

			/*if (ObjDummies[z].Envmap)
			{
				glEnd();
				
				glColor4f(0,1,0,1);
				glDisable(GL_BLEND);
				glDisable(GL_LINE_SMOOTH);
				glDisable(GL_TEXTURE_2D);
				glBlendFunc(GL_ONE,GL_ZERO);
				glDisable(GL_LIGHTING);
				glBegin(GL_LINES);
				for (x=0; x<Object->VertexNum; x++)
				{
					glVertex3f(Object->VertexList[x].MapTransformedPosition.x,Object->VertexList[x].MapTransformedPosition.y,Object->VertexList[x].MapTransformedPosition.z);
					glVertex3f(Object->VertexList[x].MapTransformedPosition.x+Object->VertexList[x].CurrentNormal.x/5.0f,
							   Object->VertexList[x].MapTransformedPosition.y+Object->VertexList[x].CurrentNormal.y/5.0f,
							   Object->VertexList[x].MapTransformedPosition.z+Object->VertexList[x].CurrentNormal.z/5.0f);
				}
				glEnd();
			}


			glBegin(GL_TRIANGLES);*/

		}
		else
		{
			glEnd();
			glPushAttrib(GL_LIGHTING_BIT);
			glPushAttrib(GL_TEXTURE_BIT);
			glDisable(GL_LIGHTING);
			glDisable(GL_TEXTURE_2D);
			glBegin(GL_LINES);
			for (x=0; x<Object->EdgeNum; x++)
				if (Object->EdgeList[x].InWireframe)
				{
					glVertex3f(Object->VertexList[Object->EdgeList[x].v1].MapTransformedPosition.x,Object->VertexList[Object->EdgeList[x].v1].MapTransformedPosition.y,Object->VertexList[Object->EdgeList[x].v1].MapTransformedPosition.z);
					glVertex3f(Object->VertexList[Object->EdgeList[x].v2].MapTransformedPosition.x,Object->VertexList[Object->EdgeList[x].v2].MapTransformedPosition.y,Object->VertexList[Object->EdgeList[x].v2].MapTransformedPosition.z);
				}
			glEnd();

			glPopAttrib();
			glPopAttrib();
			glBegin(GL_LINES);
		}

	}

	//ha elertunk minden vegere, lezarjuk a stuffot
	glEnd();
	glEndList();
}
Beispiel #5
0
void ARDrawingContext::drawCubeModel()
{
  static const GLfloat LightAmbient[]=  { 0.25f, 0.25f, 0.25f, 1.0f };    // Ambient Light Values
  static const GLfloat LightDiffuse[]=  { 0.1f, 0.1f, 0.1f, 1.0f };    // Diffuse Light Values
  static const GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };    // Light Position
  
  glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT);

  glColor4f(0.2f,0.35f,0.3f,0.75f);         // Full Brightness, 50% Alpha ( NEW )
  glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);       // Blending Function For Translucency Based On Source Alpha 
  glEnable(GL_BLEND); 

  glShadeModel(GL_SMOOTH);

  glEnable(GL_LIGHTING);
  glDisable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
  glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
  glEnable(GL_COLOR_MATERIAL);

  glScalef(0.25,0.25, 0.25);
  glTranslatef(0,0, 1);

  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  glBegin(GL_QUADS); 
  // Front Face
  glNormal3f( 0.0f, 0.0f, 1.0f);    // Normal Pointing Towards Viewer
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 1 (Front)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 2 (Front)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Front)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 4 (Front)
  // Back Face
  glNormal3f( 0.0f, 0.0f,-1.0f);    // Normal Pointing Away From Viewer
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Back)
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 2 (Back)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 3 (Back)
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 4 (Back)
  // Top Face
  glNormal3f( 0.0f, 1.0f, 0.0f);    // Normal Pointing Up
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 1 (Top)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 2 (Top)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Top)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 4 (Top)
  // Bottom Face
  glNormal3f( 0.0f,-1.0f, 0.0f);    // Normal Pointing Down
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Bottom)
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 2 (Bottom)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 3 (Bottom)
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 4 (Bottom)
  // Right face
  glNormal3f( 1.0f, 0.0f, 0.0f);    // Normal Pointing Right
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 1 (Right)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 2 (Right)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Right)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 4 (Right)
  // Left Face
  glNormal3f(-1.0f, 0.0f, 0.0f);    // Normal Pointing Left
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Left)
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 2 (Left)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 3 (Left)
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 4 (Left)
  glEnd();
  
  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  glColor4f(0.2f,0.65f,0.3f,0.35f); // Full Brightness, 50% Alpha ( NEW )
  glBegin(GL_QUADS); 
  // Front Face
  glNormal3f( 0.0f, 0.0f, 1.0f);    // Normal Pointing Towards Viewer
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 1 (Front)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 2 (Front)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Front)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 4 (Front)
  // Back Face
  glNormal3f( 0.0f, 0.0f,-1.0f);    // Normal Pointing Away From Viewer
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Back)
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 2 (Back)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 3 (Back)
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 4 (Back)
  // Top Face
  glNormal3f( 0.0f, 1.0f, 0.0f);    // Normal Pointing Up
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 1 (Top)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 2 (Top)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Top)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 4 (Top)
  // Bottom Face
  glNormal3f( 0.0f,-1.0f, 0.0f);    // Normal Pointing Down
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Bottom)
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 2 (Bottom)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 3 (Bottom)
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 4 (Bottom)
  // Right face
  glNormal3f( 1.0f, 0.0f, 0.0f);    // Normal Pointing Right
  glVertex3f( 1.0f, -1.0f, -1.0f);  // Point 1 (Right)
  glVertex3f( 1.0f,  1.0f, -1.0f);  // Point 2 (Right)
  glVertex3f( 1.0f,  1.0f,  1.0f);  // Point 3 (Right)
  glVertex3f( 1.0f, -1.0f,  1.0f);  // Point 4 (Right)
  // Left Face
  glNormal3f(-1.0f, 0.0f, 0.0f);    // Normal Pointing Left
  glVertex3f(-1.0f, -1.0f, -1.0f);  // Point 1 (Left)
  glVertex3f(-1.0f, -1.0f,  1.0f);  // Point 2 (Left)
  glVertex3f(-1.0f,  1.0f,  1.0f);  // Point 3 (Left)
  glVertex3f(-1.0f,  1.0f, -1.0f);  // Point 4 (Left)
  glEnd();
 
  glPopAttrib();
}
Beispiel #6
0
// Funciones a definir desde Effect.h
void FXritmo::perFrame(float time) {
    float t = time * 0.001f;
    float fftbass=miMusic.getFFTBass();

    glClearColor(0.925,0,0.549,1);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();

    cam.toOGL();
    cam.SetPos(0,0,-6);
    cam.SetLook(0,-1,-0.1);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();

    glLoadIdentity();

    float xt=2; // xtremo
    float z_depth=float(-0.0121);


    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glPointSize(10);
    glColor3f(1,1,1);


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

    float valy;
    int numV,j;
    Point p;
    static float pulso=0;
    int row=miMusic.getRow();
    if((row==0) || (row==1) || (row==8) || (row==9) || (row==16) || (row==17) || (row==24) || (row==25)) {
        valy=4;

    } else {
        valy=0;
    }
    if(valy>0) {
        pulso=valy;
    } else {
        if(pulso>0) {
            pulso=pulso-pulso*pulso*0.05;
        }
    }
    numV=unaEsfera.getNumVertex();

    for(j=0; j<numV; j++)
    {
        p.x = 2*sin(t*0.5 + j);
        p.y = fftbass*5 + 2*cos(t*0.5+j);
        p.z = 2*(sin(p.y)) + fftbass;
        p.w = unaEsfera.getVertex(j).w;
        unaEsfera.setVertex(j,p);
    }

    glTranslatef(0,0,pulso*0.6);
    glRotatef(t*10 ,1,1,1);
    unaEsfera.perFrame(t);

    glBlendFunc(GL_SRC_ALPHA_SATURATE, GL_ONE);

    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
    glScalef(3,3,3);
    glRotatef(t,1,0,0);
    unCubo.setPolyAlpha(0.3);
    unCubo.perFrame(t);
    glPopMatrix();
    glDisable(GL_BLEND);
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();


    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();


    for(int i=1; i<6; i++) {
        fxmotionblur->perFrame(t);
    }
    fxmotionblur->postprepareFrame();

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    xt=1.01;//10-0.05*_row; // xtremos
    miDemo->ponOrtopedico(4,4);
    float al=fmod(t,2),dp=0,dpy=-1; // desplazamiento
    glColor4f(1,1,1,pulso);
    glBindTexture(GL_TEXTURE_2D, this->layerTitle.texID);

    glBegin(GL_QUADS);
    glNormal3f( 0.0f, 0.0f, 1.0f);
    glTexCoord2f(0, 0);
    glVertex3f(-xt*2+dp,-xt+dpy,z_depth);

    glTexCoord2f(1,0);
    glVertex3f(xt*2+dp,-xt+dpy, z_depth);

    glTexCoord2f(1,1);
    glVertex3f(xt*2+dp,xt+dpy,  z_depth);

    glTexCoord2f(0,1);
    glVertex3f(-xt*2+dp,xt+dpy,z_depth);

    glEnd();
    glDisable(GL_TEXTURE_2D);
    miDemo->quitaOrtopedico();
}
Beispiel #7
0
static void draw_board(antspotlightstruct *mp)
{
  int i, j;
  double cutoff = Pi/3.0;
  double center[3];
  double centertex[2];

  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, mp->screentexture);
  glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray6);

  /* draw mesh */

  /* center is roughly spotlight position */
  center[0] = mp->ant->position[0];/* + cos(ant->direction); */
  center[1] = 0.0;
  center[2] = mp->ant->position[2];/* - 0.7*sin(ant->direction);*/

  centertex[0] = (mp->boardsize/2.0+center[0]) * mp->max_tx / mp->boardsize;
  centertex[1] = mp->max_ty - ((mp->boardsize/2.0+center[2]) * mp->max_ty / mp->boardsize);

/*   glPolygonMode(GL_FRONT, GL_LINE); */
/*   glDisable(GL_TEXTURE_2D); */

  /* 
     the vertices determined here should correspond to the illuminated
     board.  ideally the code adapts vertex distribution to the
     intensity and shape of the light.
     
     i should be finding the intersection of the cone of light and
     the board-plane.
  */
  for(i = -12; i < 12; ++i) {

    double theta1, theta2;

    glBegin(GL_TRIANGLE_STRIP);
    glNormal3f(0.0, 1.0, 0.0);

    glTexCoord2f(centertex[0], centertex[1]);
    glVertex3f(center[0], 0.01, center[2]);

    /* watch those constants */
    theta1 = mp->ant->direction + i*(cutoff/8);
    theta2 = mp->ant->direction + (i+1)*(cutoff/8);

    for(j = 1; j <= 64; ++j) {
      double point[3], tex[2];
      /* double fj = pow(1.05, j) - 1.0;*/
      double fj = j / 6.0;
      point[0] = center[0] + fj*cos(theta1);
      point[1] = 0.0;
      point[2] = center[2] - fj*sin(theta1);

      tex[0] = (mp->boardsize/2.0+point[0]) * mp->max_tx / mp->boardsize;
      tex[1] = (mp->boardsize/2.0+point[2]) * mp->max_ty / mp->boardsize;

      glTexCoord2f(tex[0], tex[1]);
      glVertex3f(point[0], point[1], point[2]);

      point[0] = center[0] + fj*cos(theta2);
      point[1] = 0.0;
      point[2] = center[2] - fj*sin(theta2);

      tex[0] = (mp->boardsize/2.0+point[0]) * mp->max_tx / mp->boardsize;
      tex[1] = (mp->boardsize/2.0+point[2]) * mp->max_ty / mp->boardsize;

      glTexCoord2f(tex[0], tex[1]);
      glVertex3f(point[0], point[1], point[2]);
    }

    glEnd();
  }

  glDisable(GL_TEXTURE_2D);
}
void SkyBox::draw()
{
	glPushMatrix();
		glPushMatrix();
			glEnable(GL_TEXTURE_2D);
				glBindTexture(GL_TEXTURE_2D, tex1);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
					glBegin(GL_QUADS);
						glNormal3f(0.0, 0.0, -1.0);

						glTexCoord2f(1.0f, 1.0f);
						glVertex3f( 0.5, 0.5, 0.5); //Top Right

						glTexCoord2f(0.0f, 1.0f);
						glVertex3f(-0.5, 0.5, 0.5); //Top Left

						glTexCoord2f(0.0f, 0.0f);
						glVertex3f(-0.5,-0.5, 0.5); //Bottom Left

						glTexCoord2f(1.0f, 0.0f);
						glVertex3f( 0.5,-0.5, 0.5); //Bottom Right
					glEnd();
			glDisable(GL_TEXTURE_2D);
		glPopMatrix();
				
		glPushMatrix();
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, tex2);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glBegin(GL_QUADS);
			glNormal3f(0.0, 0.0, 1.0);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f( 0.5,-0.5,-0.5);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(-0.5,-0.5,-0.5);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(-0.5, 0.5,-0.5);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f( 0.5, 0.5,-0.5);
			glEnd();
			glDisable(GL_TEXTURE_2D);
		glPopMatrix();
				
		glPushMatrix();
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, tex3);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glBegin(GL_QUADS);
			glNormal3f(1.0, 0.0, 0.0);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(-0.5, 0.5, 0.5);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-0.5, 0.5,-0.5);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(-0.5,-0.5,-0.5);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(-0.5,-0.5, 0.5);
			glEnd();
			glDisable(GL_TEXTURE_2D);
		glPopMatrix();
				
		glPushMatrix();
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, tex4);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glBegin(GL_QUADS);
			glNormal3f(-1.0, 0.0, 0.0);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f( 0.5, 0.5,-0.5);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f( 0.5, 0.5, 0.5);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f( 0.5,-0.5, 0.5);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f( 0.5,-0.5,-0.5);
			glEnd();
			glDisable(GL_TEXTURE_2D);
		glPopMatrix();
				
		glPushMatrix();
			glColor3f(0, 0, 0);
			glNormal3f(0.0, -1.0, 0.0);
			glVertex3f( 0.5,-0.5, 0.5);
			glVertex3f(-0.5,-0.5, 0.5);
			glVertex3f(-0.5,-0.5,-0.5);
			glVertex3f( 0.5,-0.5,-0.5);
		glPopMatrix();
			
		glPushMatrix();
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, tex5);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glBegin(GL_QUADS);
			glColor3f(1, 1, 1);
			glNormal3f(0.0, -1.0, 0.0);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f( 0.5, 0.5,-0.5);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-0.5, 0.5,-0.5);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(-0.5, 0.5, 0.5);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f( 0.5, 0.5, 0.5);
			glEnd();
			glDisable(GL_TEXTURE_2D);
		glPopMatrix();
	glPopMatrix();
}
static void Tree()
{
 const int d=5;
   int th,ph;
   
   float white[] = {1,1,1,1};
   float black[] = {0,0,0,1};
   glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec);
   glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
   glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black);

   //  Save transformation
   glPushMatrix();
   //  Offset and scale
   glTranslatef(-1.2,0.5,0);
   glScalef(0.3,0.6,0.4);
 
   glEnable(GL_TEXTURE_2D);
   glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
   glColor3f(1,1,1);
   glBindTexture(GL_TEXTURE_2D,texture[3]);
   
   for (ph=-90;ph<90;ph+=d)
   {	
      glBegin(GL_QUAD_STRIP);
      for (th=0;th<=360;th+=d)
      {
      	 glTexCoord2f(sin(th),0);
         Vertex(th,ph,0.6,0.8,0.2);
         glTexCoord2f(cos(th),1);
         Vertex(th,ph+d,0.6,0.8,0.2);
      }
      glEnd();
   }
    glPopMatrix(); 
    glDisable(GL_TEXTURE_2D);
    glPushMatrix();
    glTranslated(-0.3,-0.6,0);
    glEnable(GL_TEXTURE_2D);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
    glColor3f(1,1,1);
    glBindTexture(GL_TEXTURE_2D,texture[4]);
    //Start bark of tree
    glBegin(GL_QUADS);
    // Front
    glNormal3f(0,0,1);
    glColor3f(0.4,0.25,0.13);
    glTexCoord2f(0,0);glVertex3f(-1,0.1, 0.1);
    glTexCoord2f(1,0);glVertex3f(-0.8,0.1, 0.1);
    glTexCoord2f(1,1);glVertex3f(-0.8,0.54, 0.1);
    glTexCoord2f(0,1);glVertex3f(-1,0.54, 0.1);
   //  Back
   glNormal3f(0,0,-1);
   glColor3f(0.4,0.25,0.13);
   glTexCoord2f(0,0);glVertex3f(-0.8,0.1,0.1);
   glTexCoord2f(1,0);glVertex3f(-1,0.1,-0.1);
   glTexCoord2f(1,1);glVertex3f(-1,0.54,-0.1);
   glTexCoord2f(0,1);glVertex3f(-0.8,0.54,-0.1);
   //  Right
   glColor3f(0.4,0.25,0.13);
   glNormal3f(1,0,0);
   glTexCoord2f(0,0);glVertex3f(-0.8,0.1,0.1);
   glTexCoord2f(1,0);glVertex3f(-0.8,0.1,-0.1);
   glTexCoord2f(1,1);glVertex3f(-0.8,0.54,-0.1);
   glTexCoord2f(0,1);glVertex3f(-0.8,0.54,0.1);
   //  Left
   glColor3f(0.4,0.25,0.13);
   glNormal3f(-1,0,0);
   glTexCoord2f(0,0);glVertex3f(-1,0.1,-0.1);
   glTexCoord2f(1,0);glVertex3f(-1,0.1,0.1);
   glTexCoord2f(1,1);glVertex3f(-1,0.54,0.1);
   glTexCoord2f(0,1);glVertex3f(-1,0.54,-0.1);
   //  Top
   glColor3f(0.4,0.25,0.13);
   glNormal3f(0,1,0);
   glTexCoord2f(0,0);glVertex3f(-1,0.54,0.1);
   glTexCoord2f(1,0);glVertex3f(-0.8,0.54,0.1);
   glTexCoord2f(1,1);glVertex3f(-0.8,0.54,-0.1);
   glTexCoord2f(0,1);glVertex3f(-1,0.54,-0.1); 
   //  Bottom
   glColor3f(0.4,0.25,0.13);
   glNormal3f(0,-1,0);
   glTexCoord2f(0,0);glVertex3f(-1,0.1,-0.1);
   glTexCoord2f(1,0);glVertex3f(-0.8,0.1,-0.1);
   glTexCoord2f(1,1);glVertex3f(-0.8,0.1,0.1);
   glTexCoord2f(0,1);glVertex3f(-1,0.1,0.1);
   glEnd();
   glPopMatrix();
   glDisable(GL_TEXTURE_2D);
}
Beispiel #10
0
void TestGLContext::DrawRotatedCube(float xangle, float yangle)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -2.0f);
    glRotatef(xangle, 1.0f, 0.0f, 0.0f);
    glRotatef(yangle, 0.0f, 1.0f, 0.0f);

    // draw six faces of a cube of size 1 centered at (0, 0, 0)
    glBindTexture(GL_TEXTURE_2D, m_textures[0]);
    glBegin(GL_QUADS);
        glNormal3f( 0.0f, 0.0f, 1.0f);
        glTexCoord2f(0, 0); glVertex3f( 0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 0); glVertex3f(-0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 1); glVertex3f(-0.5f,-0.5f, 0.5f);
        glTexCoord2f(0, 1); glVertex3f( 0.5f,-0.5f, 0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[1]);
    glBegin(GL_QUADS);
        glNormal3f( 0.0f, 0.0f,-1.0f);
        glTexCoord2f(0, 0); glVertex3f(-0.5f,-0.5f,-0.5f);
        glTexCoord2f(1, 0); glVertex3f(-0.5f, 0.5f,-0.5f);
        glTexCoord2f(1, 1); glVertex3f( 0.5f, 0.5f,-0.5f);
        glTexCoord2f(0, 1); glVertex3f( 0.5f,-0.5f,-0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[2]);
    glBegin(GL_QUADS);
        glNormal3f( 0.0f, 1.0f, 0.0f);
        glTexCoord2f(0, 0); glVertex3f( 0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 0); glVertex3f( 0.5f, 0.5f,-0.5f);
        glTexCoord2f(1, 1); glVertex3f(-0.5f, 0.5f,-0.5f);
        glTexCoord2f(0, 1); glVertex3f(-0.5f, 0.5f, 0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[3]);
    glBegin(GL_QUADS);
        glNormal3f( 0.0f,-1.0f, 0.0f);
        glTexCoord2f(0, 0); glVertex3f(-0.5f,-0.5f,-0.5f);
        glTexCoord2f(1, 0); glVertex3f( 0.5f,-0.5f,-0.5f);
        glTexCoord2f(1, 1); glVertex3f( 0.5f,-0.5f, 0.5f);
        glTexCoord2f(0, 1); glVertex3f(-0.5f,-0.5f, 0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[4]);
    glBegin(GL_QUADS);
        glNormal3f( 1.0f, 0.0f, 0.0f);
        glTexCoord2f(0, 0); glVertex3f( 0.5f, 0.5f, 0.5f);
        glTexCoord2f(1, 0); glVertex3f( 0.5f,-0.5f, 0.5f);
        glTexCoord2f(1, 1); glVertex3f( 0.5f,-0.5f,-0.5f);
        glTexCoord2f(0, 1); glVertex3f( 0.5f, 0.5f,-0.5f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, m_textures[5]);
    glBegin(GL_QUADS);
        glNormal3f(-1.0f, 0.0f, 0.0f);
        glTexCoord2f(0, 0); glVertex3f(-0.5f,-0.5f,-0.5f);
        glTexCoord2f(1, 0); glVertex3f(-0.5f,-0.5f, 0.5f);
        glTexCoord2f(1, 1); glVertex3f(-0.5f, 0.5f, 0.5f);
        glTexCoord2f(0, 1); glVertex3f(-0.5f, 0.5f,-0.5f);
    glEnd();

    glFlush();

    CheckGLError();
}
Beispiel #11
0
static void gearGL(GLfloat inner_radius, GLfloat outer_radius, GLfloat width, GLint teeth, GLfloat tooth_depth)
{
	GLint i;
    GLfloat r0, r1, r2;
    GLfloat angle, da;
    GLfloat u, v, len;
	const double pi = 3.14159264;
	
    r0 = inner_radius;
    r1 = (float)(outer_radius - tooth_depth/2.0);
    r2 = (float)(outer_radius + tooth_depth/2.0);
	
    da = (float)(2.0*pi / teeth / 4.0);
	
    glShadeModel(GL_FLAT);
    glNormal3f(0.0, 0.0, 1.0);
	
    /* draw front face */
    glBegin(GL_QUAD_STRIP);
    for (i=0;i<=teeth;i++) {
		angle = (float)(i * 2.0*pi / teeth);
		glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5));
		glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5));
		glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5));
		glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5));
    }
    glEnd();
	
    /* draw front sides of teeth */
    glBegin(GL_QUADS);
    da = (float)(2.0*pi / teeth / 4.0);
    for (i=0;i<teeth;i++) {
		angle = (float)(i * 2.0*pi / teeth);
		glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5));
		glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(width*0.5));
		glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(width*0.5));
		glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5));
    }
    glEnd();
	
    glNormal3f(0.0, 0.0, -1.0);
	
	/* draw back face */
    glBegin(GL_QUAD_STRIP);
    for (i=0;i<=teeth;i++) {
		angle = (float)(i * 2.0*pi / teeth);
		glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(-width*0.5));
		glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(-width*0.5));
		glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(-width*0.5));
		glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(-width*0.5));
    }
    glEnd();
	
    /* draw back sides of teeth */
    glBegin(GL_QUADS);
    da = (float)(2.0*pi / teeth / 4.0);
    for (i=0;i<teeth;i++) {
		angle = (float)(i * 2.0*pi / teeth);
		glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(-width*0.5));
		glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(-width*0.5));
		glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(-width*0.5));
		glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(-width*0.5));
    }
    glEnd();
	
    /* draw outward faces of teeth */
    glBegin(GL_QUAD_STRIP);
    for (i=0;i<teeth;i++) {
		angle = (float)(i * 2.0*pi / teeth);
		glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(width*0.5));
		glVertex3f((float)(r1*cos(angle)), (float)(r1*sin(angle)), (float)(-width*0.5));
		u = (float)(r2*cos(angle+da) - r1*cos(angle));
		v = (float)(r2*sin(angle+da) - r1*sin(angle));
		len = (float)(sqrt(u*u + v*v));
		u /= len;
		v /= len;
		glNormal3f(v, -u, 0.0);
		glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(width*0.5));
		glVertex3f((float)(r2*cos(angle+da)), (float)(r2*sin(angle+da)), (float)(-width*0.5));
		glNormal3f((float)(cos(angle)), (float)(sin(angle)), 0.0);
		glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(width*0.5));
		glVertex3f((float)(r2*cos(angle+2*da)), (float)(r2*sin(angle+2*da)), (float)(-width*0.5));
		u = (float)(r1*cos(angle+3*da) - r2*cos(angle+2*da));
		v = (float)(r1*sin(angle+3*da) - r2*sin(angle+2*da));
		glNormal3f(v, -u, 0.0);
		glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(width*0.5));
		glVertex3f((float)(r1*cos(angle+3*da)), (float)(r1*sin(angle+3*da)), (float)(-width*0.5));
		glNormal3f((float)(cos(angle)), (float)(sin(angle)), 0.0);
    }
    glVertex3f((float)(r1*cos(0.0)), (float)(r1*sin(0.0)), (float)(width*0.5));
    glVertex3f((float)(r1*cos(0.0)), (float)(r1*sin(0.0)), (float)(-width*0.5));
    glEnd();
	
    glShadeModel(GL_SMOOTH);
	
    /* draw inside radius cylinder */
    glBegin(GL_QUAD_STRIP);
    for (i=0;i<=teeth;i++) {
		angle = (float)(i * 2.0*pi / teeth);
		glNormal3f((float)(-cos(angle)), (float)(-sin(angle)), 0.0);
		glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(-width*0.5));
		glVertex3f((float)(r0*cos(angle)), (float)(r0*sin(angle)), (float)(width*0.5));
    }
    glEnd();
}
Beispiel #12
0
/*
 =======================================================================================================================
    Draws a rectangular prism
 =======================================================================================================================
 */
void drawPrism(float x, float z, float y, float height, float width, float length)
{

	/* x face */
	glNormal3f(-1, 0, 0);
	glTexCoord2f(0.0, 0.0);
	glVertex3f(x, y, z);
	glTexCoord2f(0.0, 1.0);
	glVertex3f(x, y, z + width);
	glTexCoord2f(1.0, 1.0);
	glVertex3f(x, y + height, z + width);
	glTexCoord2f(1.0, 0.0);
	glVertex3f(x, y + height, z);

	/* z face */
	glNormal3f(0, 0, 1);
	glTexCoord2f(0.0, 0.0);
	glVertex3f(x, y, z + width);
	glTexCoord2f(0.0, 1.0);
	glVertex3f(x + length, y, z + width);
	glTexCoord2f(1.0, 1.0);
	glVertex3f(x + length, y + height, z + width);
	glTexCoord2f(1.0, 0.0);
	glVertex3f(x, y + height, z + width);

	/* x face */
	glNormal3f(1, 0, 0);
	glTexCoord2f(0.0, 0.0);
	glVertex3f(x + length, y, z + width);
	glTexCoord2f(0.0, 1.0);
	glVertex3f(x + length, y, z);
	glTexCoord2f(1.0, 1.0);
	glVertex3f(x + length, y + height, z);
	glTexCoord2f(1.0, 0.0);
	glVertex3f(x + length, y + height, z + width);

	/* z face */
	glNormal3f(0, 0, -1);
	glTexCoord2f(0.0, 0.0);
	glVertex3f(x + length, y, z);
	glTexCoord2f(0.0, 1.0);
	glVertex3f(x, y, z);
	glTexCoord2f(1.0, 1.0);
	glVertex3f(x, y + height, z);
	glTexCoord2f(1.0, 0.0);
	glVertex3f(x + length, y + height, z);

	/* top face */
	glNormal3f(0, 1, 0);
	glTexCoord2f(0.0, 0.0);
	glVertex3f(x, y + height, z);
	glTexCoord2f(0.0, 1.0);
	glVertex3f(x, y + height, z + width);
	glTexCoord2f(1.0, 1.0);
	glVertex3f(x + length, y + height, z + width);
	glTexCoord2f(1.0, 0.0);
	glVertex3f(x + length, y + height, z);

	/* bottom face */
	glNormal3f(0, -1, 0);
	glTexCoord2f(0.0, 0.0);
	glVertex3f(x, y, z);
	glTexCoord2f(0.0, 1.0);
	glVertex3f(x, y, z + width);
	glTexCoord2f(1.0, 1.0);
	glVertex3f(x + length, y, z + width);
	glTexCoord2f(1.0, 0.0);
	glVertex3f(x + length, y, z);
}
Beispiel #13
0
void glPopAttrib() {
    ERROR_IN_BLOCK();
    glstack_t *cur = tack_pop(&state.stack.attrib);
    if (cur == NULL) {
        ERROR(GL_STACK_UNDERFLOW);
    }

    if (cur->mask & GL_COLOR_BUFFER_BIT) {
#ifndef USE_ES2
        enable_disable(GL_ALPHA_TEST, cur->alpha_test);
        glAlphaFunc(cur->alpha_test_func, cur->alpha_test_ref);
#endif

        enable_disable(GL_BLEND, cur->blend);
        glBlendFunc(cur->blend_src_func, cur->blend_dst_func);

        enable_disable(GL_DITHER, cur->dither);
#ifndef USE_ES2
        enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op);
        glLogicOp(cur->logic_op);
#endif

        GLfloat *c;
        glClearColor(v4(cur->clear_color));
        glColorMask(v4(cur->color_mask));
    }

    if (cur->mask & GL_CURRENT_BIT) {
        glColor4f(v4(cur->color));
#ifndef USE_ES2
        glNormal3f(v3(cur->normal));
#endif
        for (int i = 0; i < MAX_TEX; i++) {
            glMultiTexCoord2f(GL_TEXTURE0 + i, v2(cur->tex[i]));
        }
    }

    if (cur->mask & GL_DEPTH_BUFFER_BIT) {
        enable_disable(GL_DEPTH_TEST, cur->depth_test);
        glDepthFunc(cur->depth_func);
        glClearDepth(cur->clear_depth);
        glDepthMask(cur->depth_mask);
    }

    if (cur->mask & GL_ENABLE_BIT) {
        int i;
        GLint max_clip_planes;
        glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes);
        for (i = 0; i < max_clip_planes; i++) {
            enable_disable(GL_CLIP_PLANE0 + i, *(cur->clip_planes_enabled + i));
        }

        GLint max_lights;
        glGetIntegerv(GL_MAX_LIGHTS, &max_lights);
        for (i = 0; i < max_lights; i++) {
            enable_disable(GL_LIGHT0 + i, *(cur->lights_enabled + i));
        }

        enable_disable(GL_ALPHA_TEST, cur->alpha_test);
        enable_disable(GL_BLEND, cur->blend);
        enable_disable(GL_CULL_FACE, cur->cull_face);
        enable_disable(GL_DEPTH_TEST, cur->depth_test);
        enable_disable(GL_DITHER, cur->dither);
        enable_disable(GL_FOG, cur->fog);
        enable_disable(GL_LIGHTING, cur->lighting);
        enable_disable(GL_LINE_SMOOTH, cur->line_smooth);
        enable_disable(GL_LINE_STIPPLE, cur->line_stipple);
        enable_disable(GL_COLOR_LOGIC_OP, cur->color_logic_op);
        enable_disable(GL_MULTISAMPLE, cur->multisample);
        enable_disable(GL_NORMALIZE, cur->normalize);
        enable_disable(GL_POINT_SMOOTH, cur->point_smooth);
        enable_disable(GL_POLYGON_OFFSET_FILL, cur->polygon_offset_fill);
        enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage);
        enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one);
        enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage);
        enable_disable(GL_SCISSOR_TEST, cur->scissor_test);
        enable_disable(GL_STENCIL_TEST, cur->stencil_test);
        enable_disable(GL_TEXTURE_2D, cur->texture_2d);
    }

#ifndef USE_ES2
    if (cur->mask & GL_FOG_BIT) {
        enable_disable(GL_FOG, cur->fog);
        glFogfv(GL_FOG_COLOR, cur->fog_color);
        glFogf(GL_FOG_DENSITY, cur->fog_density);
        glFogf(GL_FOG_START, cur->fog_start);
        glFogf(GL_FOG_END, cur->fog_end);
        glFogf(GL_FOG_MODE, cur->fog_mode);
    }
#endif

    if (cur->mask & GL_HINT_BIT) {
        enable_disable(GL_PERSPECTIVE_CORRECTION_HINT, cur->perspective_hint);
        enable_disable(GL_POINT_SMOOTH_HINT, cur->point_smooth_hint);
        enable_disable(GL_LINE_SMOOTH_HINT, cur->line_smooth_hint);
        enable_disable(GL_FOG_HINT, cur->fog_hint);
        enable_disable(GL_GENERATE_MIPMAP_HINT, cur->mipmap_hint);
    }

    if (cur->mask & GL_LINE_BIT) {
        enable_disable(GL_LINE_SMOOTH, cur->line_smooth);
        // TODO: stipple stuff here
        glLineWidth(cur->line_width);
    }

    if (cur->mask & GL_MULTISAMPLE_BIT) {
        enable_disable(GL_MULTISAMPLE, cur->multisample);
        enable_disable(GL_SAMPLE_ALPHA_TO_COVERAGE, cur->sample_alpha_to_coverage);
        enable_disable(GL_SAMPLE_ALPHA_TO_ONE, cur->sample_alpha_to_one);
        enable_disable(GL_SAMPLE_COVERAGE, cur->sample_coverage);
    }

#ifndef USE_ES2
    if (cur->mask & GL_POINT_BIT) {
        enable_disable(GL_POINT_SMOOTH, cur->point_smooth);
        glPointSize(cur->point_size);
    }
#endif

    if (cur->mask & GL_SCISSOR_BIT) {
        enable_disable(GL_SCISSOR_TEST, cur->scissor_test);
        glScissor(v4(cur->scissor_box));
    }

    if (cur->mask & GL_TEXTURE_BIT) {
        glBindTexture(GL_TEXTURE_2D, cur->texture);
    }

    free(cur->clip_planes_enabled);
    free(cur->clip_planes);
    free(cur->lights_enabled);
    free(cur->lights);
    free(cur);
}
Beispiel #14
0
void CRender::normal(float x, float y, float z) {
	glNormal3f(x,y,z);	
}
Beispiel #15
0
/**
 * body()
 *
 * Creates a display list for the body of a person.
 */
void body()
{
   GLfloat fan_angle;   //angle for a triangle fan
   int sections = 40;   //number of triangles in a triangle fan

   //generate a display list for a body
   body_list_id = glGenLists(1);
   //compile the new display list
   glNewList(body_list_id, GL_COMPILE);

   glPushMatrix();
      glTranslatef(0.0f, 5.05f, 0.0f);
      glRotatef(90, 1.0, 0.0, 0.0);

      //create a torso with a cylinder
      glPushMatrix();
         GLUquadricObj * torso;
         torso = gluNewQuadric();
         gluQuadricDrawStyle(torso, GLU_FILL);
         gluCylinder(torso, 1.0f, 1.0f, 2.25f, 25, 25);
      glPopMatrix();

      //triangle fan for top of body
      glPushMatrix();
         glRotatef(180.0, 0.0, 1.0, 0.0);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(cosf(fan_angle), sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //triangle fan for bottom of torso
      glPushMatrix();
         glTranslatef(0.0, 0.0, 2.25);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(cosf(fan_angle), sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //arm 1
      glPushMatrix();
         glTranslatef(1.25f, 0.0f, 0.0f);
         GLUquadricObj * arm1;
         arm1 = gluNewQuadric();
         gluQuadricDrawStyle(arm1, GLU_FILL);
         gluCylinder(arm1, 0.25f, 0.25f, 2.5f, 12, 12);
      glPopMatrix();

      //triangle fan for top of arm 1
      glPushMatrix();
         glTranslatef(1.25, 0.0, 0.0);
         glRotatef(180.0, 0.0, 1.0, 0.0);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //triangle fan for bottom of arm 1
      glPushMatrix();
         glTranslatef(1.25, 0.0, 2.5);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //arm 2
      glPushMatrix();
         glTranslatef(-1.25f, 0.0f, 0.0f);
         GLUquadricObj * arm2;
         arm2 = gluNewQuadric();
         gluQuadricDrawStyle(arm2, GLU_FILL);
         gluCylinder(arm2, 0.25f, 0.25f, 2.5f, 12, 12);
      glPopMatrix();

      //triangle fan for top of arm 2
      glPushMatrix();
         glTranslatef(-1.25, 0.0, 0.0);
         glRotatef(180.0, 0.0, 1.0, 0.0);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //triangle fan for bottom of arm 2
      glPushMatrix();
         glTranslatef(-1.25, 0.0, 2.5);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.25*cosf(fan_angle), 0.25*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //leg 1
      glPushMatrix();
         glTranslatef(0.5f, 0.0f, 2.25f);
         GLUquadricObj * leg1;
         leg1 = gluNewQuadric();
         gluQuadricDrawStyle(leg1, GLU_FILL);
         gluCylinder(leg1, 0.5f, 0.2f, 2.8f, 12, 12);
      glPopMatrix();

      //triangle fan for bottom of leg 1
      glPushMatrix();
         glTranslatef(0.5, 0.0, 5.05);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.2*cosf(fan_angle), 0.2*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

      //leg 2
      glPushMatrix();
         glTranslatef(-0.5f, 0.0f, 2.25f);
         GLUquadricObj * leg2;
         leg2 = gluNewQuadric();
         gluQuadricDrawStyle(leg2, GLU_FILL);
         gluCylinder(leg2, 0.5f, 0.2f, 2.8f, 12, 12);
      glPopMatrix();

      //triangle fan for bottom of leg 2
      glPushMatrix();
         glTranslatef(-0.5, 0.0, 5.05);
         glBegin(GL_TRIANGLE_FAN);
         glNormal3f(0.0f, 0.0f, 1.0f);
         glVertex3f(0.0f, 0.0f, 0.0f);
         sections = 12;
         for(int i = 0; i <= sections; ++i) {
            fan_angle = (GLfloat) i * 2 * PI / sections;
            glVertex3f(0.2*cosf(fan_angle), 0.2*sinf(fan_angle), 0.0f);
         }
         glEnd();
      glPopMatrix();

   glPopMatrix();

   glEndList();
}
static void walls()
{
   int th;
    float white[] = {1,1,1,1};
   float black[] = {0,0,0,1};
   glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,shinyvec);
   glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,white);
   glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,black);

   glPushMatrix();
   glScaled(0.8,3,0.8);
   
   glEnable(GL_TEXTURE_2D);
   glColor3f(1,1,1);
   glBindTexture(GL_TEXTURE_2D,texture[1]);
   
   //  Top
   glBegin(GL_TRIANGLE_FAN);
   glColor3f(1,0,0);
   glNormal3f(0,1,0);
   glVertex3f(0,1,0);
   for (th=0;th<=360;th+=15)
   glVertex3f(Cos(th),1,Sin(th));
   glEnd();
    glDisable(GL_TEXTURE_2D);
   //  Sides
  
    glEnable(GL_TEXTURE_2D);
   glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
   glColor3f(1,1,1);
   glBindTexture(GL_TEXTURE_2D,texture[0]);
   glBegin(GL_QUAD_STRIP);
     //glColor3f(1,1,1);
   for (th=0;th<=360;th+=15)
   {  glTexCoord2f(Sin(i),0);
      glNormal3f(Cos(th),1,Sin(th));
      glVertex3f(Cos(th),1,Sin(th));
       glTexCoord2f(Sin(i),1);
        glNormal3f(Cos(th),0,Sin(th));
      glVertex3f(Cos(th),0,Sin(th));
   }
   glEnd();
    glBegin(GL_TRIANGLE_FAN);
    glColor3f(1,0,0);
   glNormal3f(0,-1,0);
   glVertex3f(0,0,0);
   for (th=0;th<=360;th+=15)
      glVertex3f(Cos(th),0,Sin(th));
   glEnd();
   glPopMatrix();
    glPushMatrix();
    glPolygonOffset(-1,-1);
    glTranslated(0,0.5,0);
    glScaled(0.8,0.8,0.8);
   glEnable(GL_TEXTURE_2D);
   glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
   glColor3f(1,1,1);
   glBindTexture(GL_TEXTURE_2D,texture[1]);
     glBegin(GL_TRIANGLE_FAN);
     glColor3f(1,0,0);
         
		 glVertex3f(0,5,0);
         for (i=0;i<=360;i+=15)
         {
            glTexCoord2f(Cos(i)+0.5,Sin(i)+0.5);
            glVertex3f(Cos(i),3,Sin(i));
         }
         glEnd();
        glBegin(GL_TRIANGLE_FAN);
   glNormal3f(0,-1,0);
   glVertex3f(0,3,0);
   for (th=0;th<=360;th+=15)
      glVertex3f(Cos(th),3,Sin(th));
   glEnd();
   glPopMatrix();
    glDisable(GL_POLYGON_OFFSET_FILL);
     glDisable(GL_TEXTURE_2D);
          
}
Beispiel #17
0
void Cube:: drawTexture(){
  glBegin(GL_QUADS);
  //Top face
  glColor3f(1.0f, 1.0f, 0.0f);
  glNormal3f(0.0, 1.0f, 0.0f);
  glVertex3f(-w / 2, h / 2, -d / 2);
  glVertex3f(-w / 2, h / 2, d / 2);
  glVertex3f(w / 2, h / 2, d / 2);
  glVertex3f(w / 2, h / 2, -d / 2);
	
  //Bottom face
  glColor3f(1.0f, 0.0f, 1.0f);
  glNormal3f(0.0, -1.0f, 0.0f);
  glVertex3f(-w / 2, -h / 2, -d / 2);
  glVertex3f(w / 2, -h / 2, -d / 2);
  glVertex3f(w / 2, -h / 2, d / 2);
  glVertex3f(-w / 2, -h / 2, d / 2);
  
  //Left face
  glNormal3f(-1.0, 0.0f, 0.0f);
  glColor3f(0.0f, 1.0f, 1.0f);
  glVertex3f(-w / 2, -h / 2, -d / 2);
  glVertex3f(-w / 2, -h / 2, d / 2);
  glColor3f(0.0f, 0.0f, 1.0f);
  glVertex3f(-w / 2, h / 2, d / 2);
  glVertex3f(-w / 2, h / 2, -d / 2);
	
  //Right face
  glNormal3f(1.0, 0.0f, 0.0f);
  glColor3f(1.0f, 0.0f, 0.0f);
  glVertex3f(w / 2, -h / 2, -d / 2);
  glVertex3f(w / 2, h / 2, -d / 2);
  glColor3f(0.0f, 1.0f, 0.0f);
  glVertex3f(w / 2, h / 2, d / 2);
  glVertex3f(w / 2, -h / 2, d / 2);
	
  glEnd();
	
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D,textureId);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glColor3f(1.0f, 1.0f, 1.0f);
  glBegin(GL_QUADS);
	
  //Front face
  glNormal3f(0.0, 0.0f, 1.0f);
  glTexCoord2f(0.0f, 0.0f);
  glVertex3f(-w / 2, -h / 2, d / 2);
  glTexCoord2f(tex_width, 0.0f);
  glVertex3f(w / 2, -h / 2, d / 2);
  glTexCoord2f(tex_width, tex_height);
  glVertex3f(w / 2 , h / 2, d / 2);
  glTexCoord2f(0.0f, tex_height);
  glVertex3f(-w / 2, h / 2, d / 2);
	
  //Back face
  glNormal3f(0.0, 0.0f, -1.0f);
  glTexCoord2f(0.0f, 0.0f);
  glVertex3f(-w / 2, -h / 2, -d / 2);
  glTexCoord2f(0.0f, tex_height);
  glVertex3f(-w / 2, h / 2, -d / 2);
  glTexCoord2f(tex_width, tex_height);
  glVertex3f(w / 2, h / 2, -d / 2);
  glTexCoord2f(tex_width, 0.0f);
  glVertex3f(w / 2, -h / 2, -d / 2);
	
  glEnd();
  glDisable(GL_TEXTURE_2D);
}
Beispiel #18
0
static int
arm (GLfloat length,
     GLfloat width1, GLfloat height1,
     GLfloat width2, GLfloat height2,
     Bool wire)
{
  int polys = 0;
  glShadeModel(GL_FLAT);

#if 0  /* don't need these - they're embedded in other objects */
  /* draw end 1 */
  glFrontFace(GL_CW);
  glNormal3f(-1, 0, 0);
  glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
  glVertex3f(-length/2, -width1/2, -height1/2);
  glVertex3f(-length/2,  width1/2, -height1/2);
  glVertex3f(-length/2,  width1/2,  height1/2);
  glVertex3f(-length/2, -width1/2,  height1/2);
  polys++;
  glEnd();

  /* draw end 2 */
  glFrontFace(GL_CCW);
  glNormal3f(1, 0, 0);
  glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
  glVertex3f(length/2, -width2/2, -height2/2);
  glVertex3f(length/2,  width2/2, -height2/2);
  glVertex3f(length/2,  width2/2,  height2/2);
  glVertex3f(length/2, -width2/2,  height2/2);
  polys++;
  glEnd();
#endif

  /* draw top */
  glFrontFace(GL_CCW);
  glNormal3f(0, 0, -1);
  glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
  glVertex3f(-length/2, -width1/2, -height1/2);
  glVertex3f(-length/2,  width1/2, -height1/2);
  glVertex3f( length/2,  width2/2, -height2/2);
  glVertex3f( length/2, -width2/2, -height2/2);
  polys++;
  glEnd();

  /* draw bottom */
  glFrontFace(GL_CW);
  glNormal3f(0, 0, 1);
  glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
  glVertex3f(-length/2, -width1/2, height1/2);
  glVertex3f(-length/2,  width1/2, height1/2);
  glVertex3f( length/2,  width2/2, height2/2);
  glVertex3f( length/2, -width2/2, height2/2);
  polys++;
  glEnd();

  /* draw left */
  glFrontFace(GL_CW);
  glNormal3f(0, -1, 0);
  glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
  glVertex3f(-length/2, -width1/2, -height1/2);
  glVertex3f(-length/2, -width1/2,  height1/2);
  glVertex3f( length/2, -width2/2,  height2/2);
  glVertex3f( length/2, -width2/2, -height2/2);
  polys++;
  glEnd();

  /* draw right */
  glFrontFace(GL_CCW);
  glNormal3f(0, 1, 0);
  glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
  glVertex3f(-length/2,  width1/2, -height1/2);
  glVertex3f(-length/2,  width1/2,  height1/2);
  glVertex3f( length/2,  width2/2,  height2/2);
  glVertex3f( length/2,  width2/2, -height2/2);
  polys++;
  glEnd();

  glFrontFace(GL_CCW);

  return polys;
}
Beispiel #19
0
Datei: main.cpp Projekt: JoaoS/CG
//desenha um quadrado de lado quadsize  e normal x=1, y=2, z=3
void quad(int normal,int size,int texture, int teste)
{
    GLint i,j;
    float med_dim=(float)floor_dim/2;
    if(texture ==1)  /*se for para aplicar textura*/
    {
        glEnable(GL_TEXTURE_2D);
        if(level==0)
        {
            glBindTexture(GL_TEXTURE_2D,tex[0]);
        }
        else if(level == 1)
        {    
            glBindTexture(GL_TEXTURE_2D,tex[2]);
        }
        else
        {
            glBindTexture(GL_TEXTURE_2D,tex[4]);
        }    
        glPushMatrix();
        glBegin(GL_QUADS);

        for (int i=0;i<floor_dim*floorsize;i++)//preenche para z maior
        {   
            for (int j=0;j<floor_dim*floorsize;j++)//preenche para x maior
            {
                glNormal3f(0,1,0);
                glTexCoord2f((float)j/floor_dim,(float)i/floor_dim);              
                glVertex3d((float)j/med_dim,0,(float)i/med_dim);                
                glTexCoord2f((float)(j+1)/floor_dim,(float)i/floor_dim);              
                glVertex3d((float)(j+1)/med_dim,0,(float)i/med_dim);                    
                glTexCoord2f((float)(j+1)/floor_dim,(float)(i+1)/floor_dim);
                glVertex3d((float)(j+1)/med_dim,0,(float)(i+1)/med_dim);          
                glTexCoord2f((float)j/floor_dim,(float)(i+1)/floor_dim);
                glVertex3d((float)j/med_dim,0,(float)(i+1)/med_dim);

                if(teste==2 && j==31)
                break;
            }
            if(teste==1 && i==31)
                break;
           
        }

        glEnd();
        glPopMatrix();
        glDisable(GL_TEXTURE_2D);
    }
    else
    {    
        glBegin(GL_QUADS);
        for (i=0;i<floor_dim*multiplier;i++)
        {   
            for (j=0;j<floor_dim*multiplier;j++)
            {   
                switch(normal)
                {
                    case 1:
                        glNormal3f(1, 0, 0); // definição da normal ao polígono 
                        break;
                    case 2:
                        glNormal3f(0, 1, 0); // definição da normal ao polígono 
                        break;
                    case 3:
                        glNormal3f(0, 0, 1); // definição da normal ao polígono 
                        break;
                }
                glVertex3d((float)j/med_dim,0,(float)i/med_dim); //r[0]
                glVertex3d((float)(j+1)/med_dim,0,(float)i/med_dim); // r[1]
                glVertex3d((float)(j+1)/med_dim,0,(float)(i+1)/med_dim);
                glVertex3d((float)j/med_dim,0,(float)(i+1)/med_dim);
            }
        }
        glEnd();
    }
}
Beispiel #20
0
/* draw board */
static int drawBoard(Queenscreen *qs) 
{
  int i, j;
  int polys = 0;

  glBegin(GL_QUADS);

  for(i = 0; i < qs->BOARDSIZE; ++i)
    for(j = 0; j < qs->BOARDSIZE; ++j) {
      int par = (i-j+qs->BOARDSIZE)%2;
      glColor4f(colors[qs->colorset][par][0],
		colors[qs->colorset][par][1],
		colors[qs->colorset][par][2],
		0.70);
      glNormal3f(0.0, 1.0, 0.0);
      glVertex3f(i, 0.0, j + 1.0);
      glVertex3f(i + 1.0, 0.0, j + 1.0);
      glVertex3f(i + 1.0, 0.0, j);
      glVertex3f(i, 0.0, j);
      polys++;
    }

  glEnd();

  {
    GLfloat off = 0.01;
    GLfloat w = qs->BOARDSIZE;
    GLfloat h = 0.1;

    /* Give the board a slight lip. */
    /* #### oops, normals are wrong here, but you can't tell */

    glColor3f(0.3, 0.3, 0.3);
    glBegin (GL_QUADS);
    glVertex3f (0,  0, 0);
    glVertex3f (0, -h, 0);
    glVertex3f (0, -h, w);
    glVertex3f (0,  0, w);

    glVertex3f (0,  0, w);
    glVertex3f (0, -h, w);
    glVertex3f (w, -h, w);
    glVertex3f (w,  0, w);

    glVertex3f (w,  0, w);
    glVertex3f (w, -h, w);
    glVertex3f (w, -h, 0);
    glVertex3f (w,  0, 0);

    glVertex3f (w,  0, 0);
    glVertex3f (w, -h, 0);
    glVertex3f (0, -h, 0);
    glVertex3f (0,  0, 0);

    glVertex3f (0, -h, 0);
    glVertex3f (w, -h, 0);
    glVertex3f (w, -h, w);
    glVertex3f (0, -h, w);
    glEnd();
    polys += 4;

    /* Fill in the underside of the board with an invisible black box
       to hide the reflections that are not on tiles.  Probably there's
       a way to do this with stencils instead.
     */
    w -= off*2;
    h = 5;

    glPushMatrix();
    glTranslatef (off, 0, off);
    glDisable(GL_LIGHTING);
    glColor3f(0,0,0);
    glBegin (GL_QUADS);
    glVertex3f (0,  0, 0);
    glVertex3f (0, -h, 0);
    glVertex3f (0, -h, w);
    glVertex3f (0,  0, w);

    glVertex3f (0,  0, w);
    glVertex3f (0, -h, w);
    glVertex3f (w, -h, w);
    glVertex3f (w,  0, w);

    glVertex3f (w,  0, w);
    glVertex3f (w, -h, w);
    glVertex3f (w, -h, 0);
    glVertex3f (w,  0, 0);

    glVertex3f (w,  0, 0);
    glVertex3f (w, -h, 0);
    glVertex3f (0, -h, 0);
    glVertex3f (0,  0, 0);

    glVertex3f (0, -h, 0);
    glVertex3f (w, -h, 0);
    glVertex3f (w, -h, w);
    glVertex3f (0, -h, w);
    glEnd();
    polys += 4;
    glPopMatrix();
    if (!wire)
      glEnable(GL_LIGHTING);
  }

  return polys;
}
Beispiel #21
0
/*
 *
 *  Draw a gear wheel.  You'll probably want to call this function when
 *  building a display list since we do a lot of trig here.
 * 
 *  Input:  inner_radius - radius of hole at center
 *          outer_radius - radius at center of teeth
 *          width - width of gear
 *          teeth - number of teeth
 *          tooth_depth - depth of tooth
 */
static void
gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
     GLint teeth, GLfloat tooth_depth)
{
   GLint i;
   GLfloat r0, r1, r2;
   GLfloat angle, da;
   GLfloat u, v, len;

   r0 = inner_radius;
   r1 = outer_radius - tooth_depth / 2.0;
   r2 = outer_radius + tooth_depth / 2.0;

   da = 2.0 * M_PI / teeth / 4.0;

   glShadeModel(GL_FLAT);

   glNormal3f(0.0, 0.0, 1.0);

   /* draw front face */
   glBegin(GL_QUAD_STRIP);
   for (i = 0; i <= teeth; i++) {
      angle = i * 2.0 * M_PI / teeth;
      glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
      glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
      if (i < teeth) {
	 glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
	 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
		    width * 0.5);
      }
   }
   glEnd();

   /* draw front sides of teeth */
   glBegin(GL_QUADS);
   da = 2.0 * M_PI / teeth / 4.0;
   for (i = 0; i < teeth; i++) {
      angle = i * 2.0 * M_PI / teeth;

      glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
      glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
      glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
		 width * 0.5);
      glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
		 width * 0.5);
   }
   glEnd();

   glNormal3f(0.0, 0.0, -1.0);

   /* draw back face */
   glBegin(GL_QUAD_STRIP);
   for (i = 0; i <= teeth; i++) {
      angle = i * 2.0 * M_PI / teeth;
      glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
      glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
      if (i < teeth) {
	 glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
		    -width * 0.5);
	 glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
      }
   }
   glEnd();

   /* draw back sides of teeth */
   glBegin(GL_QUADS);
   da = 2.0 * M_PI / teeth / 4.0;
   for (i = 0; i < teeth; i++) {
      angle = i * 2.0 * M_PI / teeth;

      glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
		 -width * 0.5);
      glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
		 -width * 0.5);
      glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
      glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
   }
   glEnd();

   /* draw outward faces of teeth */
   glBegin(GL_QUAD_STRIP);
   for (i = 0; i < teeth; i++) {
      angle = i * 2.0 * M_PI / teeth;

      glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
      glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
      u = r2 * cos(angle + da) - r1 * cos(angle);
      v = r2 * sin(angle + da) - r1 * sin(angle);
      len = sqrt(u * u + v * v);
      u /= len;
      v /= len;
      glNormal3f(v, -u, 0.0);
      glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
      glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
      glNormal3f(cos(angle), sin(angle), 0.0);
      glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
		 width * 0.5);
      glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
		 -width * 0.5);
      u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
      v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
      glNormal3f(v, -u, 0.0);
      glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
		 width * 0.5);
      glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
		 -width * 0.5);
      glNormal3f(cos(angle), sin(angle), 0.0);
   }

   glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
   glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);

   glEnd();

   glShadeModel(GL_SMOOTH);

   /* draw inside radius cylinder */
   glBegin(GL_QUAD_STRIP);
   for (i = 0; i <= teeth; i++) {
      angle = i * 2.0 * M_PI / teeth;
      glNormal3f(-cos(angle), -sin(angle), 0.0);
      glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
      glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
   }
   glEnd();
}
Beispiel #22
0
void S9xOpenGLPutImage (int snes_width, int snes_height)
{
    glViewport (0, 0, GUI.window_width, GUI.window_height);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();

    glFrustum (-0.5f, 0.5f, -0.5f, 0.5f, 1.0f, 100.0f);
    glMatrixMode (GL_MODELVIEW);

    glDisable (GL_DEPTH_TEST);
    glDisable (GL_LIGHTING);
    glEnable (GL_TEXTURE_2D);
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    glDisable (GL_BLEND);

    uint8 *data = (uint8 *) GFX.Screen;

    uint32 swidth = snes_width > 256 ? 512 : 256;
    int startl = 0;

    int texture_size;

    if (OpenGL.num_textures == 2 && snes_width == 256)
        texture_size = 256;
    else
        texture_size = OpenGL.texture_size;

    uint32 pheight = snes_height % texture_size;
    if (pheight == 0)
        pheight = texture_size;

    if (OpenGL.draw_cube)
    {
        xrot += 0.3f;
        yrot += 0.2f;
        zrot += 0.4f;
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }

    for (int starty = snes_height - pheight; starty >= 0;
         startl += pheight, pheight = texture_size, starty -= texture_size)
    {
        for (int startx = 0; startx < (int) swidth; startx += texture_size)
        {
            uint32 pwidth;
            if ((pwidth = snes_width - startx) > (uint32) texture_size)
                pwidth = texture_size;

            double fx1 = (double) startx / snes_width;
            double fy1 = (double) starty / snes_height;
            double fx2 = fx1 + (double) pwidth / snes_width;
            double fy2 = fy1 + (double) pheight / snes_height;

            if (!OpenGL.packed_pixels_extension_present)
            {
                int i = 0;
                for (uint32 y = 0; y < pheight; y++)
                {
                    uint16 *ptr = (uint16 *) (GFX.Screen + (y + startl) * GFX.Pitch) + startx;
                    for (uint32 x = 0; x < pwidth; x++)
                    {
                        int color = *ptr++;
                        basetexbuffer [i  ] = RED(color);
                        basetexbuffer [i+1] = GREEN(color);
                        basetexbuffer [i+2] = BLUE(color);
                        i += 3;
                    }
                }
                data = basetexbuffer;
            }
	    else
	    if (snes_width > texture_size)
	    {
		for (uint32 y = 0; y < pheight; y++)
		{
		    memmove (basetexbuffer + sizeof (uint16) * texture_size * y,
			     (GFX.Screen + (y + startl) * GFX.Pitch) + startx,
			     sizeof (uint16) * texture_size);
		}
		data = basetexbuffer;
	    }

            if (OpenGL.num_textures == 2 && snes_width == 256)
                glBindTexture (GL_TEXTURE_2D, OpenGL.textures [1]);
            else
                glBindTexture (GL_TEXTURE_2D, OpenGL.textures [0]);

            glTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, pwidth, pheight,
                             OpenGL.format, OpenGL.type, data);

            double maxx = (double) pwidth / texture_size;
            double maxy = (double) pheight / texture_size;

            if (OpenGL.draw_cube)
            {
                glLoadIdentity();
                glTranslatef (0.0f, 0.0f, -3.5f);

                glRotatef (xrot, 1.0f, 0.0f, 0.0f);
                glRotatef (yrot, 0.0f, 1.0f, 0.0f);
                glRotatef (zrot, 0.0f, 0.0f, 1.0f);

                glBegin(GL_QUADS);
                {
                    // Front Face
                    glNormal3f (0.0f, 0.0f, 1.0f);
                    glTexCoord2f (0.0f, maxy); glVertex3f (-1.0f,-1.0f, 1.0f);
                    glTexCoord2f (maxx, maxy); glVertex3f ( 1.0f,-1.0f, 1.0f);
                    glTexCoord2f (maxx, 0.0f); glVertex3f ( 1.0f, 1.0f, 1.0f);
                    glTexCoord2f (0.0f, 0.0f); glVertex3f (-1.0f, 1.0f, 1.0f);
                    // Back Face
                    glNormal3f (0.0f, 0.0f, -1.0f);
                    glTexCoord2f (maxx, maxy); glVertex3f (-1.0f,-1.0f,-1.0f);
                    glTexCoord2f (maxx, 0.0f); glVertex3f (-1.0f, 1.0f,-1.0f);
                    glTexCoord2f (0.0f, 0.0f); glVertex3f ( 1.0f, 1.0f,-1.0f);
                    glTexCoord2f (0.0f, maxy); glVertex3f ( 1.0f,-1.0f,-1.0f);
                    // Top Face
                    glNormal3f (0.0f, 1.0f, 0.0f);
                    glTexCoord2f (0.0f, 0.0f); glVertex3f (-1.0f, 1.0f,-1.0f);
                    glTexCoord2f (0.0f, maxy); glVertex3f (-1.0f, 1.0f, 1.0f);
                    glTexCoord2f (maxx, maxy); glVertex3f ( 1.0f, 1.0f, 1.0f);
                    glTexCoord2f (maxx, 0.0f); glVertex3f ( 1.0f, 1.0f,-1.0f);
                    // Bottom Face
                    glNormal3f (0.0f, -1.0f, 0.0f);
                    glTexCoord2f (maxx, 0.0f); glVertex3f (-1.0f,-1.0f,-1.0f);
                    glTexCoord2f (0.0f, 0.0f); glVertex3f ( 1.0f,-1.0f,-1.0f);
                    glTexCoord2f (0.0f, maxy); glVertex3f ( 1.0f,-1.0f, 1.0f);
                    glTexCoord2f (maxx, maxy); glVertex3f (-1.0f,-1.0f, 1.0f);
                    // Right face
                    glNormal3f (1.0f, 0.0f, 0.0f);
                    glTexCoord2f (maxx, maxy); glVertex3f ( 1.0f,-1.0f,-1.0f);
                    glTexCoord2f (maxx, 0.0f); glVertex3f ( 1.0f, 1.0f,-1.0f);
                    glTexCoord2f (0.0f, 0.0f); glVertex3f ( 1.0f, 1.0f, 1.0f);
                    glTexCoord2f (0.0f, maxy); glVertex3f ( 1.0f,-1.0f, 1.0f);
                    // Left Face
                    glNormal3f (-1.0f, 0.0f, 0.0f);
                    glTexCoord2f (0.0f, maxy); glVertex3f (-1.0f,-1.0f,-1.0f);
                    glTexCoord2f (maxx, maxy); glVertex3f (-1.0f,-1.0f, 1.0f);
                    glTexCoord2f (maxx, 0.0f); glVertex3f (-1.0f, 1.0f, 1.0f);
                    glTexCoord2f (0.0f, 0.0f); glVertex3f (-1.0f, 1.0f,-1.0f);
                }
                glEnd();
            }
            else
            {
                glLoadIdentity ();
                glTranslatef (-0.5, -0.5, -1.0);
                glDisable (GL_DEPTH_TEST);

                glBegin(GL_TRIANGLE_STRIP);
                {
                    glTexCoord2f (0.0, maxy);
                    glVertex3f (fx1, fy1, 0.0);

                    glTexCoord2f (maxx, maxy);
                    glVertex3f (fx2, fy1, 0.0);

                    glTexCoord2f (0.0, 0.0);
                    glVertex3f (fx1, fy2, 0.0);

                    glTexCoord2f (maxx, 0.0);
                    glVertex3f (fx2, fy2, 0.0);
                }
                glEnd();
            }
        }
    }
    glXSwapBuffers (GUI.display, GUI.window);
}
void AmenBuilding::DrawBuilding() {
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texids[0]);
	glBegin(GL_QUADS);
	//draw the front face
		glNormal3f(0.0f, 0.0f, 1.0f);

		glTexCoord2f(1.0f/24.0f, 0.0f);
		glVertex3f(1.0f, 0.0f, 4.0f);
		glTexCoord2f(22.0f / 24.0f, 0.0f);
		glVertex3f(22.0f, 0.0f, 4.0f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f(24.0f, 7.0f, 4.0f);
		glTexCoord2f(0.0f, 3.0f/7.0f);
		glVertex3f(0.0f, 3.0f, 4.0f);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, texids[1]);
	glBegin(GL_QUADS);
	//draw the back face
	glNormal3f(0.0f, 0.0f, -1.0f);

	glTexCoord2f(1.0f / 12.0f, 0.0f);
	glVertex3f(22.0f, 0.0f, 0.0f);
	glTexCoord2f(23.0f / 24.0f, 0.0f);
	glVertex3f(1.0f, 0.0f, 0.0f);
	glTexCoord2f(1.0f, 3.0f/7.0f);
	glVertex3f(0.0f, 3.0f, 0.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(24.0f, 7.0f, 0.0f);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, texids[2]);
	glBegin(GL_QUADS);
	//draw the left face
	glNormal3f(-3.0f, -1.0f, 0.0f);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(1.0f, 0.0f, 0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(1.0f, 0.0f, 4.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(0.0f, 3.0f, 4.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(0.0f, 3.0f, 0.0f);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, texids[3]);
	glBegin(GL_QUADS);
	//draw the top face
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(0.0f, 3.0f, 0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(0.0f, 3.0f, 4.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f, 7.0f, 4.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(24.0f, 7.0f, 0.0f);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, texids[4]);
	glBegin(GL_QUADS);
	//draw the right face
	glNormal3f(-7.0f, -2.0f, 0.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f, 7.0f, 0.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(24.0f, 7.0f, 4.0f);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(22.0f, 0.0f, 4.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(22.0f, 0.0f, 0.0f);
	glEnd();
	glBindTexture(GL_TEXTURE_2D, 0);
	glDisable(GL_TEXTURE_2D);
}
Beispiel #24
0
void drawWoodPlanks(double width, double length, double thickness, int boardCount, int boardGap)
{
  glPushMatrix();
  glTranslated(width/2, 0, 0);
  glRotated(90,-1,0,0);
	double averageBoardWidth = 1/(boardCount*1.0);
	double currentWidth = 0;
  
  double boardColor[] = {255.0/255, 127.0/255, 36.0/255};
  glColor3dv(boardColor);
  
  // Flat so we only need 2d
  float plankCoord[(boardCount+1)*4];
  float plankTex[(boardCount+1)*4];
  
  for(int ii = 0; ii <= boardCount; ii++)
	{
    double boardWidth = (rand()%(10*int(boardCount*.7)) +
                         100-int(boardCount*.7)*5)/100.0*averageBoardWidth;
    
    if(ii == boardCount - 1)
		{
			boardWidth = 1 - currentWidth;
		}
    
    plankCoord[ii*4 + 0] = currentWidth;
    plankCoord[ii*4 + 1] = 0;
    plankCoord[ii*4 + 2] = currentWidth;
    plankCoord[ii*4 + 3] = 1;
    
    bool flipped = rand() % 2;
    plankTex[ii*4 + 0] = float(ii);
    plankTex[ii*4 + 1] = flipped;
    plankTex[ii*4 + 2] = float(ii);
    plankTex[ii*4 + 3] = 1 - flipped;
    currentWidth += boardWidth;
  }
  
  glPushMatrix();
  glRotated(-90,1,0,0);
  glTranslated(-width/2.0,0,0);
  
  if(!disableAllTextures)
	{
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, logTexture); //logEndTexture
	}
  
  glNormal3f(0, 0, -1);
  
  glEnableClientState(GL_VERTEX_ARRAY);
  if(!disableAllTextures)
  {
  	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  }
  
  // Bottom
  glPushMatrix();
  glScaled(width,length, 1);
  glVertexPointer   ( 2, GL_FLOAT, 0, plankCoord );
  glTexCoordPointer ( 2, GL_FLOAT, 0, plankTex);
  glDrawArrays(GL_QUAD_STRIP, 0, boardCount * 2 + 2);
  glPopMatrix();
  
  // Top
  glPushMatrix();
  glScaled(width,length, 1);
  glTranslated(0, 0, thickness);
  glScaled(1, 1, -1);
  glNormal3f(0, 0, -1);
  glDrawArrays(GL_QUAD_STRIP, 0, boardCount * 2 + 2);
  glPopMatrix();
  
  // Front
  glPushMatrix();
  //glTranslated(0, 0, thickness);
  glRotated(90,1,0,0);
  glScaled(width, thickness, -1);
  glNormal3f(0, 0, -1);
  glDrawArrays(GL_QUAD_STRIP, 0, boardCount * 2 + 2);
  glPopMatrix();
  
  // Back
  glPushMatrix();
  glTranslated(0, length, 0);
  glRotated(90,1,0,0);
  glScaled(width, thickness, 1);
  glNormal3f(0, 0, -1);
  glDrawArrays(GL_QUAD_STRIP, 0, boardCount * 2 + 2);
  glPopMatrix();
  
  // left
  glPushMatrix();
  glTranslated(0, 0, thickness);
  glRotated(90,0,0,1);
  glRotated(-90,1,0,0);
  glScaled(length, thickness, -1);
  glNormal3f(0, 0, -1);
  glDrawArrays(GL_QUAD_STRIP, 0, boardCount * 2 + 2);
  glPopMatrix();
  
  // right
  glPushMatrix();
  glTranslated(width, 0, thickness);
  glRotated(90,0,0,1);
  glRotated(-90,1,0,0);
  glScaled(length, thickness, 1);
  glNormal3f(0, 0, -1);
  glDrawArrays(GL_QUAD_STRIP, 0, boardCount * 2 + 2);
  glPopMatrix();
  
  glDisableClientState(GL_VERTEX_ARRAY);
  if(!disableAllTextures)
  {
  	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  }
  glPopMatrix();
  if(!disableAllTextures)
  {
    glDisable(GL_TEXTURE_2D);
  }
  glPopMatrix();
}
void EDA_3D_CANVAS::buildShadowList( GLuint aFrontList, GLuint aBacklist, GLuint aBoardList )
{
    // Board shadows are based on board dimension.

    float xmin    = m_boardAABBox.Min().x;
    float xmax    = m_boardAABBox.Max().x;
    float ymin    = m_boardAABBox.Min().y;
    float ymax    = m_boardAABBox.Max().y;

    float zpos = GetPrm3DVisu().GetLayerZcoordBIU( F_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits;

    // Shadow FRONT
    glNewList( aFrontList, GL_COMPILE );

    glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( F_Paste ) );

    glBegin (GL_QUADS);
    glTexCoord2f( 1.0, 0.0 ); glVertex3f( xmin, ymin, zpos );
    glTexCoord2f( 0.0, 0.0 ); glVertex3f( xmax, ymin, zpos );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( xmax, ymax, zpos );
    glTexCoord2f( 1.0, 1.0 ); glVertex3f( xmin, ymax, zpos );
    glEnd();

    glEndList();


    // Shadow BACK
    zpos = GetPrm3DVisu().GetLayerZcoordBIU( B_Paste ) * GetPrm3DVisu().m_BiuTo3Dunits;

    glNewList( aBacklist, GL_COMPILE );

    glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( B_Paste ) );

    glBegin (GL_QUADS);
    glTexCoord2f( 0.0, 0.0 ); glVertex3f( xmin, ymin, zpos );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( xmin, ymax, zpos );
    glTexCoord2f( 1.0, 1.0 ); glVertex3f( xmax, ymax, zpos );
    glTexCoord2f( 1.0, 0.0 ); glVertex3f( xmax, ymin, zpos );
    glEnd();

    glEndList();

    // Shadow BOARD

    // Floor shadow is based on axis alighned bounding box dimension
    xmin = m_fastAABBox_Shadow.Min().x;
    xmax = m_fastAABBox_Shadow.Max().x;
    ymin = m_fastAABBox_Shadow.Min().y;
    ymax = m_fastAABBox_Shadow.Max().y;

    glNewList( aBoardList, GL_COMPILE );
    glNormal3f( 0.0, 0.0, Get3DLayer_Z_Orientation( F_Paste ) );

    glBegin (GL_QUADS);
    glTexCoord2f( 1.0, 0.0 ); glVertex3f( xmin, ymin, m_fastAABBox_Shadow.Min().z );
    glTexCoord2f( 0.0, 0.0 ); glVertex3f( xmax, ymin, m_fastAABBox_Shadow.Min().z );
    glTexCoord2f( 0.0, 1.0 ); glVertex3f( xmax, ymax, m_fastAABBox_Shadow.Min().z );
    glTexCoord2f( 1.0, 1.0 ); glVertex3f( xmin, ymax, m_fastAABBox_Shadow.Min().z );
    glEnd();

    glEndList();
}
void IceFloe::drawGeom() {	
	int i, j;
	float h;

	h = height * TransIcelandicExpress::c_RoadLevel;	

	// draw the sides	
	sgVec3 edge, n, up;
	sgSetVec3( up, 0.0, 1.0, 0.0 );
	glBegin( GL_QUADS );
	for (j = npnts-1, i = 0; i < npnts; j=i++) {
		sgSetVec3( edge, pnts[j][0] - pnts[i][0], 0.0,
						 pnts[j][2] - pnts[i][2] );

		sgNormalizeVec3( edge );
		sgVectorProductVec3( n, edge, up );
	
		glNormal3f( n[0], n[1], n[2] );

		glVertex3f( pnts[i][0], h, pnts[i][2] );
		glVertex3f( pnts[j][0], h, pnts[j][2] );
		glVertex3f( pnts[j][0], 0.0, pnts[j][2] );
		glVertex3f( pnts[i][0], 0.0, pnts[i][2] );						
	}
	glEnd();

	// tesselate the top
	if (!tess.size()) {
		if (!gluTess) {

			gluTess = gluNewTess();
			gluTessCallback( gluTess, GLU_BEGIN,  (void(__stdcall *)(void))tessBegin );
			gluTessCallback( gluTess, GLU_END,    (void(__stdcall *)(void))tessEnd );
			gluTessCallback( gluTess, GLU_VERTEX, (void(__stdcall *)(void))tessVertex );
			gluTessCallback( gluTess, GLU_ERROR,  (void(__stdcall *)(void))tessError );
		}

		printf("Tesselating polygon....\n");
		floeToTess = this;

		gluBeginPolygon( gluTess );
		GLdouble *v;
		for (i = 0; i < npnts; i++) {
			pnts[i][1] = h;

			v = new GLdouble[4];
			v[0] = pnts[i][0]; 
			v[1] = pnts[i][1]; 
			v[2] = pnts[i][2];			

			printf("gluTessVertex %3.4f %3.4f %3.4f\n",
				v[0], v[1], v[2] );
			gluTessVertex( gluTess, v, pnts[i] );
		}
		printf("About to call end....\n");
		gluEndPolygon( gluTess );
		printf("Done.\n");

		floeToTess = NULL;
	} 

	// draw the top
	glNormal3f( 0.0, 1.0, 0.0 );
	glBegin( GL_TRIANGLES );	
	for (std::vector<TessTri*>::iterator ti = tess.begin();
		 ti != tess.end(); ti++ ) {

		glVertex3f( (*ti)->a[0], (*ti)->a[1], (*ti)->a[2] );
		glVertex3f( (*ti)->b[0], (*ti)->b[1], (*ti)->b[2] );
		glVertex3f( (*ti)->c[0], (*ti)->c[1], (*ti)->c[2] );

	}
	glEnd();

}
 //core elements
 static void arch() {

   int i, numSlices;
   double angle;
   double angInc;

   glPushMatrix();
   glTranslatef(0,0.5,0);
   glScalef(4,1,2);
   glutSolidCube(1);
   glPopMatrix();

   glPushMatrix();
   glTranslatef(-1.5,-1 ,0);
   glScalef(1,4,2);
   glutSolidCube(1);
   glPopMatrix();

   glPushMatrix();
   glTranslatef(1.5, -1,0);
   glScalef(1,4,2);
   glutSolidCube(1);
   glPopMatrix();
	glPushMatrix();
	glMaterialfv(GL_FRONT, GL_AMBIENT, blueWindows);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, blueWindows);
	glTranslatef(0,-1.5,0);
	glScalef(2,3.25,0.125);
	glutSolidCube(1);
	glMaterialfv(GL_FRONT, GL_AMBIENT, brickMat);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, brickMat);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0,-1.75,0);
	glScalef(3.0,0.25,0.25);
	glutSolidCube(1);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(0.5,-2,0);
	glScalef(0.25,4,0.25);
	glutSolidCube(1);
	glPopMatrix();
	glPushMatrix();
	glTranslatef(-0.5,-2,0);
	glScalef(0.25,4,0.25);
	glutSolidCube(1);
	glPopMatrix();

   numSlices = 20;
   angle = 0;
   angInc = 3.14159/(2 * numSlices);

   for (i = 0; i < numSlices; i++) {

	   glNormal3f(0,0,1);
       glBegin(GL_POLYGON);
       glVertex3f(1,0,1);  // corner
       glVertex3f( cos(angle) , sin(angle)-1, 1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, 1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(-1,0,1);  // corner
       glVertex3f(- cos(angle) , sin(angle)-1, 1);
       glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, 1);
       glEnd();

	   //---
	   glNormal3f(0,0,-1);
       glBegin(GL_POLYGON);
       glVertex3f(1,0,-1);  // corner
       glVertex3f( cos(angle) , sin(angle)-1, -1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(-1,0,-1);  // corner
       glVertex3f(- cos(angle) , sin(angle)-1, -1);
       glVertex3f(- cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

	   // vault

	   glNormal3f(-cos(angle+angInc/2),-sin(angle+angInc/2),0);


	   glColor3f(0,0,1);
       glBegin(GL_POLYGON);
       glVertex3f(  cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( cos(angle) ,       sin(angle)-1, -1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f(  cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( cos(angle+angInc) ,       sin(angle+angInc)-1, 1);
       glVertex3f( cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

	   glNormal3f(cos(angle+angInc/2),-sin(angle+angInc/2),0);

       glBegin(GL_POLYGON);
       glVertex3f( - cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( -cos(angle) ,       sin(angle)-1, -1);
       glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();

       glBegin(GL_POLYGON);
       glVertex3f( - cos(angle) ,    sin(angle)-1 ,1);  // corner
       glVertex3f( -cos(angle+angInc) ,       sin(angle+angInc)-1, 1);
       glVertex3f( -cos(angle+angInc), sin(angle+angInc)-1, -1);
       glEnd();



	   angle += angInc;
   
   }
}
Beispiel #28
0
void RenderScene() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The matrix

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	// Give OpenGL our position,	then view,		then up vector
	gluLookAt(		0, 1.5f, 8,		0, 0.5f, 0,			0, 1, 0);
	
	// We want the model to rotate around the axis so we give it a rotation
	// value, then increase/decrease it. You can rotate right of left with the arrow keys.

	glRotatef(g_RotateX, 0, 1.0f, 0);						// Rotate the object around the Y-Axis
	g_RotateX += g_RotationSpeed;							// Increase the speed of rotation

	// I am going to attempt to explain what is going on below up here as not to clutter the 
	// code below.  We have a model that has a certain amount of objects and textures.  We want 
	// to go through each object in the model, bind it's texture map to it, then render it.
	// To render the current object, we go through all of it's faces (Polygons).  
	// What is a face you ask?  A face is just (in this case) a triangle of the object.
	// For instance, a cube has 12 faces because each side has 2 triangles.
	// You might be thinking.  Well, if there are 12 faces in a cube, that makes
	// 36 vertices that we needed to read in for that object.  Not really true.  Because
	// a lot of the vertices are the same, since they share sides, they only need to save
	// 8 vertices, and ignore the duplicates.  Then, you have an array of all the
	// unique vertices in that object.  No 2 vertices will be the same.  This cuts down
	// on memory.  Then, another array is saved, which is the index numbers for each face,
	// which index in to that array of vertices.  That might sound silly, but it is better
	// than saving tons of duplicate vertices.  The same thing happens for UV coordinates.
	// You don't save duplicate UV coordinates, you just save the unique ones, then an array
	// that index's into them.  This might be confusing, but most 3D files use this format.
	// This loop below will stay the same for most file formats that you load, so all you need
	// to change is the loading code.  You don't need to change this loop (Except for animation).

	// Since we know how many objects our model has, go through each of them.
	for(int i = 0; i < g_3DModel.numOfObjects; i++)
	{
		// Make sure we have valid objects just in case. (size() is in the vector class)
		if(g_3DModel.pObject.size() <= 0) break;

		// Get the current object that we are displaying
		t3DObject *pObject = &g_3DModel.pObject[i];
			
		// Check to see if this object has a texture map, if so bind the texture to it.
		if(pObject->bHasTexture) {

			// Turn on texture mapping and turn off color
			glEnable(GL_TEXTURE_2D);

			// Reset the color to normal again
			glColor3ub(255, 255, 255);

			// Bind the texture map to the object by it's materialID
			glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]);
		} else {

			// Turn off texture mapping and turn on color
			glDisable(GL_TEXTURE_2D);

			// Reset the color to normal again
			glColor3ub(255, 255, 255);
		}

		// This determines if we are in wireframe or normal mode
		glBegin(g_ViewMode);					// Begin drawing with our selected mode (triangles or lines)

			// Go through all of the faces (polygons) of the object and draw them
			for(int j = 0; j < pObject->numOfFaces; j++)
			{
				// Go through each corner of the triangle and draw it.
				for(int whichVertex = 0; whichVertex < 3; whichVertex++)
				{
					// Get the index for each point of the face
					int index = pObject->pFaces[j].vertIndex[whichVertex];
			
					// Give OpenGL the normal for this vertex.
					glNormal3f(pObject->pNormals[ index ].x, pObject->pNormals[ index ].y, pObject->pNormals[ index ].z);
				
					// If the object has a texture associated with it, give it a texture coordinate.
					if(pObject->bHasTexture) {

						// Make sure there was a UVW map applied to the object or else it won't have tex coords.
						if(pObject->pTexVerts) {
							glTexCoord2f(pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
						}
					} else {

						// Make sure there is a valid material/color assigned to this object.
						// You should always at least assign a material color to an object, 
						// but just in case we want to check the size of the material list.
						// if the size is at least one, and the material ID != -1,
						// then we have a valid material.
						if(g_3DModel.pMaterials.size() && pObject->materialID >= 0) 
						{
							// Get and set the color that the object is, since it must not have a texture
							BYTE *pColor = g_3DModel.pMaterials[pObject->materialID].color;

							// Assign the current color to this model
							glColor3ub(pColor[0], pColor[1], pColor[2]);
						}
					}

					// Pass in the current vertex of the object (Corner of current face)
					glVertex3f(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);
				}
			}

		glEnd();								// End the drawing
	}


//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	SwapBuffers(g_hDC);									// Swap the backbuffers to the foreground
}
Beispiel #29
0
void processNode(Object* object){

	//Transformacoes
	glPushMatrix();
	glMultMatrixf(object->m_object);

	//Material
	if(object->material->id == "null"){
		if(materials.empty())
			cout << "Erro! Não há materiais na stack!" << endl;
		else{
			Material* mat = materials.top();
			mat->setMaterial();
		}
	} else{
		object->material->setMaterial();
		materials.push(object->material);
	}
	
	if(object->type == "simple"){ //Desenhar os poligonos
		Simple* simple = (Simple*)object;
		
		//Texturas
		if(object->texture->id != "null")
			textures.push(object->texture);
		if((object->texture->id != "clear") && (textures.top()->id != "clear")){
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, textures.top()->number);
		}
		
		//Triangulo
		if(simple->polygon->type == "triangle"){
			Triangle* triangle = (Triangle*)simple->polygon;
			float* n = newell(triangle);
			
			float length_A = sqrt((triangle->x2-triangle->x1)*(triangle->x2-triangle->x1) + (triangle->y2-triangle->y1)*(triangle->y2-triangle->y1) + (triangle->z2-triangle->z1)*(triangle->z2-triangle->z1));
			float length_B = sqrt((triangle->x3-triangle->x1)*(triangle->x3-triangle->x1) + (triangle->y3-triangle->y1)*(triangle->y3-triangle->y1) + (triangle->z3-triangle->z1)*(triangle->z3-triangle->z1));
			float length_N = sqrt(n[0]*n[0] + n[1]*n[1] + n[2]*n[2]);

			double height = length_N / length_A;

			double width = sqrt(length_B*length_B - height*height);
	
			glBegin(GL_POLYGON);
				glNormal3f(n[0],n[1],n[2]);
				glTexCoord2d(triangle->x1/textures.top()->length_s, triangle->y1/textures.top()->length_t); glVertex3d(triangle->x1, triangle->y1, triangle->z1);
				glTexCoord2d((triangle->x1 + length_A)/textures.top()->length_s, triangle->y1/textures.top()->length_t); glVertex3d(triangle->x2, triangle->y2, triangle->z2);
				glTexCoord2d((triangle->x1 + width)/textures.top()->length_s, (triangle->y1 + height)/textures.top()->length_t);glVertex3d(triangle->x3, triangle->y3, triangle->z3);
			glEnd();
		}
		//Rectangulo
		if(simple->polygon->type == "rectangle"){
			Rectangle* rect = (Rectangle*)simple->polygon;
			float s = mapText(rect->x1, rect->x2, textures.top()->length_s);
			float t = mapText(rect->y1, rect->y2, textures.top()->length_t);
			glBegin(GL_POLYGON);
				glNormal3d(0.0,0.0,1.0);
				glTexCoord2f(0.0,0.0);glVertex2d(rect->x1, rect->y1);
				glTexCoord2f(s  ,0.0);glVertex2d(rect->x2, rect->y1);
				glTexCoord2f(s  ,t  );glVertex2d(rect->x2, rect->y2);
				glTexCoord2f(0.0,t  );glVertex2d(rect->x1, rect->y2);
			glEnd();
		}

		if(simple->polygon->type == "cylinder"){
			Cylinder* cyl = (Cylinder*)simple->polygon;
			gluCylinder(glQ, cyl->base, cyl->top, cyl->height, cyl->slices, cyl->stacks);
		}
		if(simple->polygon->type == "sphere"){
			Sphere* sphere = (Sphere*)simple->polygon;
			gluSphere(glQ, sphere->radius, sphere->slices, sphere->stacks);
		}
		if(simple->polygon->type == "disk"){
			Disk* disk = (Disk*)simple->polygon;
			gluDisk(glQ, disk->inner, disk->outer, disk->slices, disk->loops);
		}
		glDisable(GL_TEXTURE_2D);
		
	}else if(object->type == "compound"){
		if(object->texture->id != "null"){
			textures.push(object->texture);
		}
		Compound* compound = (Compound*)object;
		vector<Object*>::iterator it = compound->childrenObj.begin();
		for( ; it != compound->childrenObj.end(); it++){
			processNode(*it);
		}
	}
	if(object->material->id != "null") materials.pop();
	if(object->texture->id != "null") textures.pop(); 
	glPopMatrix();	
}
Beispiel #30
0
void renderTextures()
{
   // bind the FBO for rendering
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

   // save the viewport and set to the size of the texture
   glPushAttrib(GL_VIEWPORT_BIT);
   glViewport(0, 0, texWidth, texHeight);

   // render to the FBO
   glClearColor( 0.0f, 0.0f, 0.0f, 0.5f);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();

   glTranslatef(0.0f, 0.0f, -2.0f);
   glRotatef(xrot, 1.0f, 0.0f, 0.0f);
   glRotatef(yrot, 0.0f, 1.0f, 0.0f);

   // enable shader program
   mrtprogram->use();
   glBegin(GL_QUADS);
      // front face
      glNormal3f( 0.0f, 0.0f, 1.0);
      glColor4f( 0.0f, 1.0f, 0.0f, 1.0f );
      glVertex3f(-0.5f, -0.5f,  0.5f);
      glVertex3f( 0.5f, -0.5f,  0.5f);
      glVertex3f( 0.5f,  0.5f,  0.5f);
      glVertex3f(-0.5f,  0.5f,  0.5f);
      // Back face
      glNormal3f( 0.0f, 0.0f,-1.0);
      glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
      glVertex3f(-0.5f, -0.5f, -0.5f);
      glVertex3f(-0.5f,  0.5f, -0.5f);
      glVertex3f( 0.5f,  0.5f, -0.5f);
      glVertex3f( 0.5f, -0.5f, -0.5f);
      // Top face
      glNormal3f( 0.0f, 1.0, 0.0f);
      glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
      glVertex3f(-0.5f,  0.5f, -0.5f);
      glVertex3f(-0.5f,  0.5f,  0.5f);
      glVertex3f( 0.5f,  0.5f,  0.5f);
      glVertex3f( 0.5f,  0.5f, -0.5f);
      // Bottom face
      glNormal3f( 0.0f,-1.0, 0.0f);
      glColor4f(0.0f,1.0f,1.0f,1.0f);
      glVertex3f(-0.5f, -0.5f, -0.5f);
      glVertex3f( 0.5f, -0.5f, -0.5f);
      glVertex3f( 0.5f, -0.5f,  0.5f);
      glVertex3f(-0.5f, -0.5f,  0.5f);
      // Right face
      glNormal3f( 1.0, 0.0f, 0.0f);
      glColor4f(1.0f,1.0f,0.0f,1.0f);
      glVertex3f( 0.5f, -0.5f, -0.5f);
      glVertex3f( 0.5f,  0.5f, -0.5f);
      glVertex3f( 0.5f,  0.5f,  0.5f);
      glVertex3f( 0.5f, -0.5f,  0.5f);
      // Left Face
      glNormal3f(-1.0, 0.0f, 0.0f);
      glColor4f(1.0f,1.0f,1.0f,1.0f);
      glVertex3f(-0.5, -0.5f, -0.5f);
      glVertex3f(-0.5, -0.5f,  0.5f);
      glVertex3f(-0.5,  0.5f,  0.5f);
      glVertex3f(-0.5,  0.5f, -0.5f);
   glEnd();
   // disable shader program
   mrtprogram->disable();

   // Restore old viewport and set rendering back to default fb
   glPopAttrib();
   glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

}