void executeRenderCommands(bool windowed,int message,void* data)
{
	if (message==sim_message_eventcallback_extrenderer_start)
	{
		// Collect camera and environment data from V-REP:
		void** valPtr=(void**)data;
		resolutionX=((int*)valPtr[0])[0];
		resolutionY=((int*)valPtr[1])[0];
		float* backgroundColor=((float*)valPtr[2]);
		float viewAngle=((float*)valPtr[8])[0];
		perspectiveOperation=(((int*)valPtr[5])[0]==0);
		nearClippingPlane=((float*)valPtr[9])[0];
		farClippingPlane=((float*)valPtr[10])[0];
		float* amb=(float*)valPtr[11];
		C7Vector cameraTranformation(C4Vector((float*)valPtr[4]),C3Vector((float*)valPtr[3]));
		C4X4Matrix m4(cameraTranformation.getMatrix());
		float* fogBackgroundColor=(float*)valPtr[12];
		int fogType=((int*)valPtr[13])[0];
		float fogStart=((float*)valPtr[14])[0];
		float fogEnd=((float*)valPtr[15])[0];
		float fogDensity=((float*)valPtr[16])[0];
		bool fogEnabled=((bool*)valPtr[17])[0];
		float orthoViewSize=((float*)valPtr[18])[0];
		visionSensorOrCameraId=((int*)valPtr[19])[0];
		int posX=0;
		int posY=0;
		if ((valPtr[20]!=NULL)&&(valPtr[21]!=NULL))
		{
			posX=((int*)valPtr[20])[0];
			posY=((int*)valPtr[21])[0];
		}
		float fogDistance=((float*)valPtr[22])[0]; // pov-ray
		float fogTransp=((float*)valPtr[23])[0]; // pov-ray
		bool povFocalBlurEnabled=((bool*)valPtr[24])[0]; // pov-ray
		float povFocalDistance=((float*)valPtr[25])[0]; // pov-ray
		float povAperture=((float*)valPtr[26])[0]; // pov-ray
		int povBlurSamples=((int*)valPtr[27])[0]; // pov-ray

		COpenglBase* oglItem=NULL;
		if (windowed&&_simulationRunning)
		{
			COpenglWidget* oglWidget=getWidget(visionSensorOrCameraId);
			if (oglWidget==NULL)
			{
				oglWidget=new COpenglWidget(visionSensorOrCameraId);
				oglWidgets.push_back(oglWidget);

				oglWidget->initGL();
				oglWidget->showAtGivenSizeAndPos(resolutionX,resolutionY,posX,posY);
			}

			// the window size can change, we return those values:
			oglWidget->getWindowResolution(resolutionX,resolutionY);
			((int*)valPtr[0])[0]=resolutionX;
			((int*)valPtr[1])[0]=resolutionY;

			oglItem=oglWidget;
		}
		else
		{ // non-windowed
			COpenglOffscreen* oglOffscreen=getOffscreen(visionSensorOrCameraId);
			if (oglOffscreen!=NULL)
			{
				if (!oglOffscreen->isResolutionSame(resolutionX,resolutionY))
				{
					removeOffscreen(visionSensorOrCameraId);
					oglOffscreen=NULL;
				}
			}
			if (oglOffscreen==NULL)
			{
				oglOffscreen=new COpenglOffscreen(visionSensorOrCameraId,resolutionX,resolutionY);
				oglOffscreens.push_back(oglOffscreen);

				oglOffscreen->initGL();
			}
			oglItem=oglOffscreen;
		}

		if (oglItem!=NULL)
		{
			oglItem->makeContextCurrent();
			oglItem->clearBuffers(viewAngle,orthoViewSize,nearClippingPlane,farClippingPlane,perspectiveOperation,backgroundColor);

			if (meshContainer==NULL)
			{
				meshContainer=new COcMeshContainer();
				textureContainer=new COcTextureContainer();
			}

			// The following instructions have the same effect as gluLookAt()
			m4.inverse();
			m4.rotateAroundY(3.14159265359f);
			float m4_[4][4];
			m4.copyTo(m4_);
			#define SWAP(a,b) {temp=(a);(a)=(b);(b)=temp;}
			float temp;
			SWAP(m4_[0][1],m4_[1][0]);
			SWAP(m4_[0][2],m4_[2][0]);
			SWAP(m4_[0][3],m4_[3][0]);
			SWAP(m4_[1][2],m4_[2][1]);
			SWAP(m4_[1][3],m4_[3][1]);
			SWAP(m4_[2][3],m4_[3][2]);
			#undef SWAP
			glLoadMatrixf((float*)m4_);

			GLfloat ambient[4]={amb[0],amb[1],amb[2],1.0f};
			glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient);

			if (fogEnabled)
			{
				float fog_color[4]={fogBackgroundColor[0],fogBackgroundColor[1],fogBackgroundColor[2],1.0f};
				GLenum fogTypeEnum[3]={GL_LINEAR,GL_EXP,GL_EXP2};
				glFogfv(GL_FOG_COLOR,fog_color);
				glFogi(GL_FOG_MODE,fogTypeEnum[fogType]);
				glFogf(GL_FOG_START,fogStart);
				glFogf(GL_FOG_END,fogEnd);
				glFogf(GL_FOG_DENSITY,fogDensity);
				glEnable(GL_FOG);
			}
			activeLightCounter=0;
		}
	}

	if (message==sim_message_eventcallback_extrenderer_light)
	{
		// Collect light data from V-REP (one light at a time):
		void** valPtr=(void**)data;
		int lightType=((int*)valPtr[0])[0];
		float cutoffAngle=((float*)valPtr[1])[0];
		int spotExponent=((int*)valPtr[2])[0];
		float* colors=((float*)valPtr[3]);
		float constAttenuation=((float*)valPtr[4])[0];
		float linAttenuation=((float*)valPtr[5])[0];
		float quadAttenuation=((float*)valPtr[6])[0];
		C7Vector lightTranformation(C4Vector((float*)valPtr[8]),C3Vector((float*)valPtr[7]));
		float lightSize=((float*)valPtr[9])[0];
		float FadeXDistance=((float*)valPtr[10])[0]; // Pov-ray
		bool lightIsVisible=((bool*)valPtr[11])[0];
		bool noShadow=((bool*)valPtr[12])[0]; // Pov-ray

		if (_simulationRunning||(!windowed))
		{ // Now set-up that light in OpenGl:
			C4X4Matrix m(lightTranformation.getMatrix());
			GLfloat lightPos[]={0.0f,0.0f,0.0f,1.0f};
			GLfloat lightDir[3];
			if (lightType==sim_light_directional_subtype)
			{
				lightPos[0]=-m.M.axis[2](0);
				lightPos[1]=-m.M.axis[2](1);
				lightPos[2]=-m.M.axis[2](2);
				lightPos[3]=0.0f;
			}
			else
			{
				lightPos[0]=m.X(0);
				lightPos[1]=m.X(1);
				lightPos[2]=m.X(2);
				lightPos[3]=1.0f;
			}
			lightDir[0]=m.M.axis[2](0);
			lightDir[1]=m.M.axis[2](1);
			lightDir[2]=m.M.axis[2](2);
			glLightfv(GL_LIGHT0+activeLightCounter,GL_POSITION,lightPos);
			glLightfv(GL_LIGHT0+activeLightCounter,GL_SPOT_DIRECTION,lightDir);
			if (lightType==sim_light_omnidirectional_subtype)
				glLightf(GL_LIGHT0+activeLightCounter,GL_SPOT_CUTOFF,180.0f);
			if (lightType==sim_light_directional_subtype)
				glLightf(GL_LIGHT0+activeLightCounter,GL_SPOT_CUTOFF,90.0f);
			if (lightType==sim_light_spot_subtype)
			{
				float coa=cutoffAngle*radToDeg;
				if (coa>89.0f) // 90.0f causes problems on MacOS!!!
				coa=89.0f;
				glLightf(GL_LIGHT0+activeLightCounter,GL_SPOT_CUTOFF,coa);
			}
			glLightf(GL_LIGHT0+activeLightCounter,GL_SPOT_EXPONENT,float(spotExponent)); // glLighti & GL_SPOT_EXPONENT causes problems on MacOS!!!
			float black[4]={0.0f,0.0f,0.0f,1.0f};
			glLightfv(GL_LIGHT0+activeLightCounter,GL_AMBIENT,black);
			float diffuseLight[4]={colors[3],colors[4],colors[5],1.0f};
			glLightfv(GL_LIGHT0+activeLightCounter,GL_DIFFUSE,diffuseLight);
			float specularLight[4]={colors[6],colors[7],colors[8],1.0f};
			glLightfv(GL_LIGHT0+activeLightCounter,GL_SPECULAR,specularLight);
			glLightf(GL_LIGHT0+activeLightCounter,GL_CONSTANT_ATTENUATION,constAttenuation);
			glLightf(GL_LIGHT0+activeLightCounter,GL_LINEAR_ATTENUATION,linAttenuation);
			glLightf(GL_LIGHT0+activeLightCounter,GL_QUADRATIC_ATTENUATION,quadAttenuation);
			glEnable(GL_LIGHT0+activeLightCounter);
			activeLightCounter++;
		}
	}

	if (message==sim_message_eventcallback_extrenderer_mesh)
	{
		// Collect mesh data from V-REP:
		void** valPtr=(void**)data;
		float* vertices=((float*)valPtr[0]);
		int verticesCnt=((int*)valPtr[1])[0];
		int* indices=((int*)valPtr[2]);
		int triangleCnt=((int*)valPtr[3])[0];
		float* normals=((float*)valPtr[4]);
		int normalsCnt=((int*)valPtr[5])[0];
		float* colors=((float*)valPtr[8]);
		C7Vector tr(C4Vector((float*)valPtr[7]),C3Vector((float*)valPtr[6]));
		bool textured=((bool*)valPtr[18])[0];
		float shadingAngle=((float*)valPtr[19])[0];
		unsigned int meshId=((unsigned int*)valPtr[20])[0];
		bool translucid=((bool*)valPtr[21])[0];
		float opacityFactor=((float*)valPtr[22])[0];
		bool backfaceCulling=((bool*)valPtr[23])[0];
		int geomId=((int*)valPtr[24])[0];
		int texId=((int*)valPtr[25])[0];
		unsigned char* edges=((unsigned char*)valPtr[26]);
		bool visibleEdges=((bool*)valPtr[27])[0];
		// valPtr[28] is reserved
		int povPatternType=((int*)valPtr[29])[0]; // pov-ray
		int displayAttrib=((int*)valPtr[30])[0];
		const char* colorName=((char*)valPtr[31]);

		if (_simulationRunning||(!windowed))
		{
			float* texCoords=NULL;
			int texCoordCnt=0;
			bool repeatU=false;
			bool repeatV=false;
			bool interpolateColors=false;
			int applyMode=0;
			COcTexture* theTexture=NULL;
			if (textured)
			{
				// Read some additional data from V-REP (i.e. texture data):
				texCoords=((float*)valPtr[9]);
				texCoordCnt=((int*)valPtr[10])[0];
				unsigned char* textureBuff=((unsigned char*)valPtr[11]); // RGBA
				int textureSizeX=((int*)valPtr[12])[0];
				int textureSizeY=((int*)valPtr[13])[0];
				repeatU=((bool*)valPtr[14])[0];
				repeatV=((bool*)valPtr[15])[0];
				interpolateColors=((bool*)valPtr[16])[0];
				applyMode=((int*)valPtr[17])[0];

				theTexture=textureContainer->getFromId(texId);
				if (theTexture==NULL)
				{
					theTexture=new COcTexture(texId,textureBuff,textureSizeX,textureSizeY);
					textureContainer->add(theTexture);
				}
			}
			COcMesh* mesh=meshContainer->getFromId(geomId);
			if (mesh==NULL)
			{
				mesh=new COcMesh(geomId,vertices,verticesCnt*3,indices,triangleCnt*3,normals,normalsCnt*3,texCoords,texCoordCnt*2, edges);
				meshContainer->add(mesh);
			}

			mesh->render(tr,colors,textured,shadingAngle,translucid,opacityFactor,backfaceCulling,repeatU,repeatV,interpolateColors,applyMode,theTexture,visibleEdges);
		}
	}

	if (message==sim_message_eventcallback_extrenderer_triangles)
	{
		// Collect mesh data from V-REP:
		void** valPtr=(void**)data;
		float* vertices=((float*)valPtr[0]);
		int verticesCnt=((int*)valPtr[1])[0];
		float* normals=((float*)valPtr[2]);
		float* colors=((float*)valPtr[3]);
		bool translucid=((bool*)valPtr[4])[0];
		float opacityFactor=((float*)valPtr[5])[0];
		int povPatternType=((int*)valPtr[6])[0]; // pov-ray

		if (_simulationRunning||(!windowed))
		{ // Now display the mesh with above data:
			glMateriali(GL_FRONT_AND_BACK,GL_SHININESS,48);
			float ambientDiffuse[4]={colors[0],colors[1],colors[2],opacityFactor};
			glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,ambientDiffuse);
			float specular[4]={colors[6],colors[7],colors[8],1.0f};
			glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular);
			float emission[4]={colors[9],colors[10],colors[11],1.0f};
			glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission);

			if (translucid)
			{
				glEnable(GL_BLEND);
				glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			}

			glBegin(GL_TRIANGLES);
			for (int i=0;i<verticesCnt/3;i++)
			{
				glNormal3fv(normals+3*i);
				glVertex3fv(vertices+9*i+0);
				glVertex3fv(vertices+9*i+3);
				glVertex3fv(vertices+9*i+6);
			}
			glEnd();
			glDisable(GL_BLEND);
		}
	}

	if (message==sim_message_eventcallback_extrenderer_stop)
	{
		void** valPtr=(void**)data;
		unsigned char* rgbBuffer=((unsigned char*)valPtr[0]);
		float* depthBuffer=((float*)valPtr[1]);
		bool readRgb=((bool*)valPtr[2])[0];
		bool readDepth=((bool*)valPtr[3])[0];

		if (windowed)
		{
			if (_simulationRunning)
			{
				COpenglWidget* oglWidget=getWidget(visionSensorOrCameraId);
				if (oglWidget!=NULL)
				{
					oglWidget->swapBuffers();
					oglWidget->doneCurrentContext();
				}
			}
		}
		else
		{
			COpenglOffscreen* oglOffscreen=getOffscreen(visionSensorOrCameraId);
			if (oglOffscreen!=NULL)
			{
				if (readRgb)
				{
					glPixelStorei(GL_PACK_ALIGNMENT,1);
					glReadPixels(0,0,resolutionX,resolutionY,GL_RGB,GL_UNSIGNED_BYTE,rgbBuffer);
					glPixelStorei(GL_PACK_ALIGNMENT,4);
				}
				if (readDepth)
				{
					glReadPixels(0,0,resolutionX,resolutionY,GL_DEPTH_COMPONENT,GL_FLOAT,depthBuffer);
					// Convert this depth info into values corresponding to linear depths (if perspective mode):
					if (perspectiveOperation)
					{
						float farMinusNear= farClippingPlane-nearClippingPlane;
						float farDivFarMinusNear=farClippingPlane/farMinusNear;
						float nearTimesFar=nearClippingPlane*farClippingPlane;
						int v=resolutionX*resolutionY;
						for (int i=0;i<v;i++)
							depthBuffer[i]=((nearTimesFar/(farMinusNear*(farDivFarMinusNear-depthBuffer[i])))-nearClippingPlane)/farMinusNear;
					}
				}
				oglOffscreen->doneCurrentContext();
			}
		}

		if (_simulationRunning||(!windowed))
		{
			meshContainer->decrementAllUsedCount();
			meshContainer->removeAllUnused();
			textureContainer->decrementAllUsedCount();
			textureContainer->removeAllUnused();
		}
	}
}
Example #2
0
static void
Fish001(GLenum cap)
{
	glBegin(cap);
	glNormal3fv(N005);
	glVertex3fv(P005);
	glNormal3fv(N059);
	glVertex3fv(P059);
	glNormal3fv(N060);
	glVertex3fv(P060);
	glNormal3fv(N006);
	glVertex3fv(P006);
	glEnd();
	glBegin(cap);
	glNormal3fv(N015);
	glVertex3fv(P015);
	glNormal3fv(N005);
	glVertex3fv(P005);
	glNormal3fv(N006);
	glVertex3fv(P006);
	glNormal3fv(N016);
	glVertex3fv(P016);
	glEnd();
	glBegin(cap);
	glNormal3fv(N006);
	glVertex3fv(P006);
	glNormal3fv(N060);
	glVertex3fv(P060);
	glNormal3fv(N008);
	glVertex3fv(P008);
	glEnd();
	glBegin(cap);
	glNormal3fv(N016);
	glVertex3fv(P016);
	glNormal3fv(N006);
	glVertex3fv(P006);
	glNormal3fv(N008);
	glVertex3fv(P008);
	glEnd();
	glBegin(cap);
	glNormal3fv(N016);
	glVertex3fv(P016);
	glNormal3fv(N008);
	glVertex3fv(P008);
	glNormal3fv(N017);
	glVertex3fv(P017);
	glEnd();
	glBegin(cap);
	glNormal3fv(N017);
	glVertex3fv(P017);
	glNormal3fv(N008);
	glVertex3fv(P008);
	glNormal3fv(N018);
	glVertex3fv(P018);
	glEnd();
	glBegin(cap);
	glNormal3fv(N008);
	glVertex3fv(P008);
	glNormal3fv(N009);
	glVertex3fv(P009);
	glNormal3fv(N018);
	glVertex3fv(P018);
	glEnd();
	glBegin(cap);
	glNormal3fv(N008);
	glVertex3fv(P008);
	glNormal3fv(N060);
	glVertex3fv(P060);
	glNormal3fv(N009);
	glVertex3fv(P009);
	glEnd();
	glBegin(cap);
	glNormal3fv(N007);
	glVertex3fv(P007);
	glNormal3fv(N010);
	glVertex3fv(P010);
	glNormal3fv(N009);
	glVertex3fv(P009);
	glEnd();
	glBegin(cap);
	glNormal3fv(N009);
	glVertex3fv(P009);
	glNormal3fv(N019);
	glVertex3fv(P019);
	glNormal3fv(N018);
	glVertex3fv(P018);
	glEnd();
	glBegin(cap);
	glNormal3fv(N009);
	glVertex3fv(P009);
	glNormal3fv(N010);
	glVertex3fv(P010);
	glNormal3fv(N019);
	glVertex3fv(P019);
	glEnd();
	glBegin(cap);
	glNormal3fv(N010);
	glVertex3fv(P010);
	glNormal3fv(N020);
	glVertex3fv(P020);
	glNormal3fv(N019);
	glVertex3fv(P019);
	glEnd();
	glBegin(cap);
	glNormal3fv(N010);
	glVertex3fv(P010);
	glNormal3fv(N011);
	glVertex3fv(P011);
	glNormal3fv(N021);
	glVertex3fv(P021);
	glNormal3fv(N020);
	glVertex3fv(P020);
	glEnd();
	glBegin(cap);
	glNormal3fv(N004);
	glVertex3fv(P004);
	glNormal3fv(N011);
	glVertex3fv(P011);
	glNormal3fv(N010);
	glVertex3fv(P010);
	glNormal3fv(N007);
	glVertex3fv(P007);
	glEnd();
	glBegin(cap);
	glNormal3fv(N004);
	glVertex3fv(P004);
	glNormal3fv(N012);
	glVertex3fv(P012);
	glNormal3fv(N011);
	glVertex3fv(P011);
	glEnd();
	glBegin(cap);
	glNormal3fv(N012);
	glVertex3fv(P012);
	glNormal3fv(N022);
	glVertex3fv(P022);
	glNormal3fv(N011);
	glVertex3fv(P011);
	glEnd();
	glBegin(cap);
	glNormal3fv(N011);
	glVertex3fv(P011);
	glNormal3fv(N022);
	glVertex3fv(P022);
	glNormal3fv(N021);
	glVertex3fv(P021);
	glEnd();
	glBegin(cap);
	glNormal3fv(N059);
	glVertex3fv(P059);
	glNormal3fv(N005);
	glVertex3fv(P005);
	glNormal3fv(N015);
	glVertex3fv(P015);
	glEnd();
	glBegin(cap);
	glNormal3fv(N015);
	glVertex3fv(P015);
	glNormal3fv(N014);
	glVertex3fv(P014);
	glNormal3fv(N003);
	glVertex3fv(P003);
	glEnd();
	glBegin(cap);
	glNormal3fv(N015);
	glVertex3fv(P015);
	glNormal3fv(N003);
	glVertex3fv(P003);
	glNormal3fv(N059);
	glVertex3fv(P059);
	glEnd();
	glBegin(cap);
	glNormal3fv(N014);
	glVertex3fv(P014);
	glNormal3fv(N013);
	glVertex3fv(P013);
	glNormal3fv(N003);
	glVertex3fv(P003);
	glEnd();
	glBegin(cap);
	glNormal3fv(N003);
	glVertex3fv(P003);
	glNormal3fv(N012);
	glVertex3fv(P012);
	glNormal3fv(N059);
	glVertex3fv(P059);
	glEnd();
	glBegin(cap);
	glNormal3fv(N013);
	glVertex3fv(P013);
	glNormal3fv(N012);
	glVertex3fv(P012);
	glNormal3fv(N003);
	glVertex3fv(P003);
	glEnd();
	glBegin(cap);
	glNormal3fv(N013);
	glVertex3fv(P013);
	glNormal3fv(N022);
	glVertex3fv(P022);
	glNormal3fv(N012);
	glVertex3fv(P012);
	glEnd();
	glBegin(cap);
	glVertex3fv(P071);
	glVertex3fv(P072);
	glVertex3fv(P073);
	glVertex3fv(P074);
	glVertex3fv(P075);
	glVertex3fv(P076);
	glEnd();
	glBegin(cap);
	glVertex3fv(P077);
	glVertex3fv(P078);
	glVertex3fv(P079);
	glVertex3fv(P080);
	glVertex3fv(P081);
	glVertex3fv(P082);
	glEnd();
}
Example #3
0
static void
Fish003(GLenum cap)
{
	glBegin(cap);
	glNormal3fv(N032);
	glVertex3fv(P032);
	glNormal3fv(N023);
	glVertex3fv(P023);
	glNormal3fv(N033);
	glVertex3fv(P033);
	glNormal3fv(N042);
	glVertex3fv(P042);
	glEnd();
	glBegin(cap);
	glNormal3fv(N031);
	glVertex3fv(P031);
	glNormal3fv(N032);
	glVertex3fv(P032);
	glNormal3fv(N042);
	glVertex3fv(P042);
	glNormal3fv(N041);
	glVertex3fv(P041);
	glEnd();
	glBegin(cap);
	glNormal3fv(N023);
	glVertex3fv(P023);
	glNormal3fv(N024);
	glVertex3fv(P024);
	glNormal3fv(N034);
	glVertex3fv(P034);
	glNormal3fv(N033);
	glVertex3fv(P033);
	glEnd();
	glBegin(cap);
	glNormal3fv(N024);
	glVertex3fv(P024);
	glNormal3fv(N025);
	glVertex3fv(P025);
	glNormal3fv(N035);
	glVertex3fv(P035);
	glNormal3fv(N034);
	glVertex3fv(P034);
	glEnd();
	glBegin(cap);
	glNormal3fv(N030);
	glVertex3fv(P030);
	glNormal3fv(N031);
	glVertex3fv(P031);
	glNormal3fv(N041);
	glVertex3fv(P041);
	glNormal3fv(N040);
	glVertex3fv(P040);
	glEnd();
	glBegin(cap);
	glNormal3fv(N025);
	glVertex3fv(P025);
	glNormal3fv(N026);
	glVertex3fv(P026);
	glNormal3fv(N036);
	glVertex3fv(P036);
	glNormal3fv(N035);
	glVertex3fv(P035);
	glEnd();
	glBegin(cap);
	glNormal3fv(N026);
	glVertex3fv(P026);
	glNormal3fv(N027);
	glVertex3fv(P027);
	glNormal3fv(N037);
	glVertex3fv(P037);
	glNormal3fv(N036);
	glVertex3fv(P036);
	glEnd();
	glBegin(cap);
	glNormal3fv(N027);
	glVertex3fv(P027);
	glNormal3fv(N028);
	glVertex3fv(P028);
	glNormal3fv(N038);
	glVertex3fv(P038);
	glNormal3fv(N037);
	glVertex3fv(P037);
	glEnd();
	glBegin(cap);
	glNormal3fv(N028);
	glVertex3fv(P028);
	glNormal3fv(N029);
	glVertex3fv(P029);
	glNormal3fv(N039);
	glVertex3fv(P039);
	glNormal3fv(N038);
	glVertex3fv(P038);
	glEnd();
	glBegin(cap);
	glNormal3fv(N029);
	glVertex3fv(P029);
	glNormal3fv(N030);
	glVertex3fv(P030);
	glNormal3fv(N040);
	glVertex3fv(P040);
	glNormal3fv(N039);
	glVertex3fv(P039);
	glEnd();
}
Example #4
0
static void Animate(void)
{
    struct coord *coord;
    struct facet *facet;
    float *lastColor;
    float *thisColor;
    GLint i, j;

    glClear(clearMask);

    if (nextFrame || !stepMode) {
	curFrame++;
    }
    if (curFrame >= theMesh.frames) {
	curFrame = 0;
    }

    if ((nextFrame || !stepMode) && spinMode) {
	glRotatef(5.0, 0.0, 0.0, 1.0);
    }
    nextFrame = 0;

    for (i = 0; i < theMesh.widthX; i++) {
	glBegin(GL_QUAD_STRIP);
	lastColor = NULL;
	for (j = 0; j < theMesh.widthY; j++) {
	    facet = GETFACET(curFrame, i, j);
	    if (!smooth && lighting) {
		glNormal3fv(facet->normal);
	    }
	    if (lighting) {
		if (rgb) {
		    thisColor = facet->color;
		    glColor3fv(facet->color);
		} else {
		    thisColor = facet->color;
		    glMaterialfv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES,
				 facet->color);
		}
	    } else {
		if (rgb) {
		    thisColor = facet->color;
		    glColor3fv(facet->color);
		} else {
		    thisColor = facet->color;
		    glIndexf(facet->color[1]);
		}
	    }

	    if (!lastColor || (thisColor[0] != lastColor[0] && smooth)) {
		if (lastColor) {
		    glEnd();
		    glBegin(GL_QUAD_STRIP);
		}
		coord = GETCOORD(curFrame, i, j);
		if (smooth && lighting) {
		    glNormal3fv(coord->normal);
		}
		glVertex3fv(coord->vertex);

		coord = GETCOORD(curFrame, i+1, j);
		if (smooth && lighting) {
		    glNormal3fv(coord->normal);
		}
		glVertex3fv(coord->vertex);
	    }

	    coord = GETCOORD(curFrame, i, j+1);
	    if (smooth && lighting) {
		glNormal3fv(coord->normal);
	    }
	    glVertex3fv(coord->vertex);

	    coord = GETCOORD(curFrame, i+1, j+1);
	    if (smooth && lighting) {
		glNormal3fv(coord->normal);
	    }
	    glVertex3fv(coord->vertex);

	    lastColor = thisColor;
	}
	glEnd();
    }

    glFlush();
    if (doubleBuffer) {
	glutSwapBuffers();
    }
}
Example #5
0
static void
Fish007(GLenum cap)
{
	glBegin(cap);
	glNormal3fv(N062);
	glVertex3fv(P062);
	glNormal3fv(N022);
	glVertex3fv(P022);
	glNormal3fv(N032);
	glVertex3fv(P032);
	glEnd();
	glBegin(cap);
	glNormal3fv(N062);
	glVertex3fv(P062);
	glNormal3fv(N032);
	glVertex3fv(P032);
	glNormal3fv(N064);
	glVertex3fv(P064);
	glEnd();
	glBegin(cap);
	glNormal3fv(N022);
	glVertex3fv(P022);
	glNormal3fv(N062);
	glVertex3fv(P062);
	glNormal3fv(N032);
	glVertex3fv(P032);
	glEnd();
	glBegin(cap);
	glNormal3fv(N062);
	glVertex3fv(P062);
	glNormal3fv(N064);
	glVertex3fv(P064);
	glNormal3fv(N032);
	glVertex3fv(P032);
	glEnd();
}
Example #6
0
void do_display (void)
{
    int i,j,s,t, tmp;
    cum_al = 0.0;

    metaal_texture();

    for (s=0;s<24;s += 2)
    {
	t = s+2;
	if (!(t&7))
	    t=t-8;

	if (s == 16)
	    rood_texture();
	glBegin(GL_QUADS);
	for (i=0;i<tot;i=j)
	{
	    tmp = 0;
	    for (j=i+1;j<tot;j++)
		if ((tmp=tmp+tmp+opt[j]) > 4000 || (!(j%(3*DIST))))
		    break;

	    if (j>=tot)
		j = 0;

	    rr++;
	    VERTEX(s, j);
	    VERTEX(s, i);
	    VERTEX(t, i);
	    VERTEX(t, j);
	    if (!j)
		break;
	}
	glEnd();
    }
    printf("Split up to %d parts.\n", rr);
    rood_texture();
    for (i=0;i<tot-2;i+=DIST)
    {
	if (!(i%(DIST*5)))
	    continue;

	glBegin(GL_QUADS);
	glNormal3fv(bnormal[0][i]);
	glVertex3fv(strips[24][i]);
	glVertex3fv(strips[24][i+5]);
	glVertex3fv(strips[26][i+5]);
	glVertex3fv(strips[26][i]);

	glNormal3fv(bnormal[1][i]);
	glVertex3fv(strips[25][i]);
	glVertex3fv(strips[25][i+5]);
	glVertex3fv(strips[26][i+5]);
	glVertex3fv(strips[26][i]);
	glEnd();
    }

    wit_texture();
    for (i=0;i<tot-2;i+=DIST)
    {
	if (i%(DIST*5))
	    continue;

	glBegin(GL_QUADS);
	glNormal3fv(bnormal[0][i]);
	glVertex3fv(strips[24][i]);
	glVertex3fv(strips[24][i+5]);
	glVertex3fv(strips[26][i+5]);
	glVertex3fv(strips[26][i]);

	glNormal3fv(bnormal[1][i]);
	glVertex3fv(strips[25][i]);
	glVertex3fv(strips[25][i+5]);
	glVertex3fv(strips[26][i+5]);
	glVertex3fv(strips[26][i]);
	glEnd();
    }

    groen_texture();
    glBegin(GL_QUADS);
    for (i=0;i<tot;i+=90)
    {
	if (dy[i]<0.2)
	    continue;
	glNormal3f(-1.0, 0.0, 0.0);
	glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]-0.7);
	glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]-0.2);
	glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]+0.2);
	glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]+0.7);

	glNormal3f(0.0, 0.0, 1.0);
	glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]+0.7);
	glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]+0.2);
	glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]+0.2);
	glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]+0.7);

	glNormal3f(0.0, 0.0, -1.0);
	glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]-0.7);
	glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]-0.2);
	glVertex3f(strips[22][i][0]-0.2,strips[16][i][1],strips[22][i][2]-0.2);
	glVertex3f(strips[22][i][0]-0.7,-4,strips[22][i][2]-0.7);

	glNormal3f(1.0, 0.0, 0.0);
	glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]-0.7);
	glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]-0.2);
	glVertex3f(strips[22][i][0]+0.2,strips[16][i][1],strips[22][i][2]+0.2);
	glVertex3f(strips[22][i][0]+0.7,-4,strips[22][i][2]+0.7);
    }
    glEnd();
}
Example #7
0
void display(void)
{
   GLfloat white_light_pos[] = {32.876, 0.0, -81.376, 1.0};
   GLfloat white_spot_dir[] = {-0.457936, 0.0, 0.888985};
   GLfloat red_light_pos[] = {-32.517, -58.405, -102.872, 1.0};
   GLfloat red_spot_dir[] = {0.0, 0.513511, 0.858083};
   GLfloat blue_light_pos[] = {-32.517, 58.405, -102.872, 1.0};
   GLfloat blue_spot_dir[] = {0.0, -0.513511, 0.858083};
   GLfloat white_light_pos2[] = {32.876, 0.0, 59.874, 1.0};
   GLfloat white_spot_dir2[] = {-0.457936, 0.0, -0.888985};
   GLfloat mat_white[] = {1.0, 1.0, 1.0, 1.0};
   GLfloat mat_brown[] = {0.745, 0.416, 0.17, 1.0};
   GLfloat mat_black[] = {0.0, 0.0, 0.0, 1.0};
   GLfloat emission_yeux[] = {0.3, 0.3, 0.3, 0.0};
   GLfloat emission_def[] = {0.0, 0.0, 0.0, 1.0};

   GLint i;

   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glPushMatrix();

   gluLookAt(150.0, 0.0, 10.0, 0.0, 0.0, 10.0, 0.0, 0.0, 1.0);

   glRotatef(angle1, 1.0, 0.0, 0.0);
   glTranslatef(-20.0, 0.0, 0.0);
   glRotatef(angle2, 0.0, 1.0, 0.0);
   glTranslatef(20.0, 0.0, 0.0);

   glTranslatef(proche_x, proche_y, proche_z);

   glLightfv(GL_LIGHT0, GL_POSITION, white_light_pos);
   glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, white_spot_dir);
   glLightfv(GL_LIGHT1, GL_POSITION, red_light_pos);
   glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, red_spot_dir);
   glLightfv(GL_LIGHT2, GL_POSITION, blue_light_pos);
   glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, blue_spot_dir);
   glLightfv(GL_LIGHT3, GL_POSITION, white_light_pos2);
   glLightfv(GL_LIGHT3, GL_SPOT_DIRECTION, white_spot_dir2);


   /* affichage du visage */

   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_white);
   glVertexPointer(3, GL_FLOAT, 0, vertices);
   glEnableClientState(GL_NORMAL_ARRAY);
   glNormalPointer(GL_FLOAT, 0, norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_BOX01, GL_UNSIGNED_INT, faces);


   /* affichage des blancs d'yeux */

   glMaterialfv(GL_FRONT, GL_EMISSION, emission_yeux);

   glVertexPointer(3, GL_FLOAT, 0, eye_vertices);
   glNormalPointer(GL_FLOAT, 0, eye_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_GEO1, GL_UNSIGNED_INT, eye_faces);

   glPushMatrix();
   glTranslatef(0.0, 24.918, 0.0);
   glDrawElements(GL_TRIANGLES, 3*FACES_GEO1, GL_UNSIGNED_INT, eye_faces);
   glPopMatrix();

   glMaterialfv(GL_FRONT, GL_EMISSION, emission_def);


   /* affichage des iris */

   glPushMatrix();
   glTranslatef(-8.372, -12.459, 20.538);
   glRotatef(angleYeux, 0.0, 0.0, 1.0);
   glTranslatef(8.372, 12.459, -20.538);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_brown);
   glVertexPointer(3, GL_FLOAT, 0, iris_vertices);
   glDisableClientState (GL_NORMAL_ARRAY);
   for (i=0; i<FACES_CONE02; i++)
   {
      glNormal3fv(&iris_norm[3*i]);
      glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, &iris_faces[i][0]);
   }
   glPopMatrix();

   glPushMatrix();
   glTranslatef(0.0, 24.918, 0.0);
   glTranslatef(-8.372, -12.459, 20.538);
   glRotatef(angleYeux, 0.0, 0.0, 1.0);
   glTranslatef(8.372, 12.459, -20.538);
   glVertexPointer(3, GL_FLOAT, 0, iris_vertices);
   for (i=0; i<FACES_CONE02; i++)
   {
      glNormal3fv(&iris_norm[3*i]);
      glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, &iris_faces[i][0]);
   }
   glPopMatrix();


   /* affichage des pupilles */

   glPushMatrix();
   glTranslatef(-8.372, -12.459, 20.538);
   glRotatef(angleYeux, 0.0, 0.0, 1.0);
   glTranslatef(8.372, 12.459, -20.538);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_black);
   glDrawElements(GL_POLYGON, 24, GL_UNSIGNED_INT, pupil);
   glPopMatrix();

   glPushMatrix();
   glTranslatef(0.0, 24.918, 0.0);
   glTranslatef(-8.372, -12.459, 20.538);
   glRotatef(angleYeux, 0.0, 0.0, 1.0);
   glTranslatef(8.372, 12.459, -20.538);
   glDrawElements(GL_POLYGON, 24, GL_UNSIGNED_INT, pupil);
   glPopMatrix();


   /* affichage des dents du bas */

   glEnable(GL_LIGHT3);

   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_white);
   glVertexPointer(3, GL_FLOAT, 0, dent01_vertices);
   glEnableClientState (GL_NORMAL_ARRAY);
   glNormalPointer(GL_FLOAT, 0, dent01_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT01, GL_UNSIGNED_INT, dent01_faces);
   glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, dent01_faces4);

   glVertexPointer(3, GL_FLOAT, 0, dent02_vertices);
   glNormalPointer(GL_FLOAT, 0, dent02_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT01, GL_UNSIGNED_INT, dent01_faces);
   glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, dent01_faces4);

   glVertexPointer(3, GL_FLOAT, 0, dent03_vertices);
   glNormalPointer(GL_FLOAT, 0, dent03_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT01, GL_UNSIGNED_INT, dent01_faces);
   glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, dent01_faces4);

   glVertexPointer(3, GL_FLOAT, 0, dent04_vertices);
   glNormalPointer(GL_FLOAT, 0, dent04_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT04, GL_UNSIGNED_INT, dent04_faces);

   glVertexPointer(3, GL_FLOAT, 0, dent05_vertices);
   glNormalPointer(GL_FLOAT, 0, dent05_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT04, GL_UNSIGNED_INT, dent04_faces);

   glVertexPointer(3, GL_FLOAT, 0, dent06_vertices);
   glNormalPointer(GL_FLOAT, 0, dent06_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT06, GL_UNSIGNED_INT, dent06_faces);

   glVertexPointer(3, GL_FLOAT, 0, dent07_vertices);
   glNormalPointer(GL_FLOAT, 0, dent07_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT06, GL_UNSIGNED_INT, dent06_faces);

   glDisable(GL_LIGHT3);


   /* affichage des dents du haut */

   glVertexPointer(3, GL_FLOAT, 0, dent08_vertices);
   glNormalPointer(GL_FLOAT, 0, dent08_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT08, GL_UNSIGNED_INT, dent08_faces);
   glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, dent08_faces4);

   glVertexPointer(3, GL_FLOAT, 0, dent09_vertices);
   glNormalPointer(GL_FLOAT, 0, dent09_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT08, GL_UNSIGNED_INT, dent08_faces);
   glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, dent08_faces4);

   glVertexPointer(3, GL_FLOAT, 0, dent10_vertices);
   glNormalPointer(GL_FLOAT, 0, dent10_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT10, GL_UNSIGNED_INT, dent10_faces);
   glDrawElements(GL_QUADS, 8, GL_UNSIGNED_INT, dent10_faces4);

   glVertexPointer(3, GL_FLOAT, 0, dent11_vertices);
   glNormalPointer(GL_FLOAT, 0, dent11_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT11, GL_UNSIGNED_INT, dent11_faces);

   glVertexPointer(3, GL_FLOAT, 0, dent12_vertices);
   glNormalPointer(GL_FLOAT, 0, dent12_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT11, GL_UNSIGNED_INT, dent11_faces);

   glVertexPointer(3, GL_FLOAT, 0, dent13_vertices);
   glNormalPointer(GL_FLOAT, 0, dent13_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT13, GL_UNSIGNED_INT, dent13_faces);

   glVertexPointer(3, GL_FLOAT, 0, dent14_vertices);
   glNormalPointer(GL_FLOAT, 0, dent14_norm);
   glDrawElements(GL_TRIANGLES, 3*FACES_DENT13, GL_UNSIGNED_INT, dent13_faces);


   glPopMatrix();

   glutSwapBuffers();
}
void recursive_render (const struct aiScene *sc, const struct aiNode* nd, float scale)
{
	unsigned int i;
	unsigned int n=0, t;
	aiMatrix4x4 m = nd->mTransformation;

	m.Scaling(aiVector3D(scale, scale, scale), m);

	// update transform
	m.Transpose();
	glPushMatrix();
	glMultMatrixf((float*)&m);

	// draw all meshes assigned to this node
	for (; n < nd->mNumMeshes; ++n)
	{
		const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];

		apply_material(sc->mMaterials[mesh->mMaterialIndex]);


		if(mesh->mNormals == NULL)
		{
			glDisable(GL_LIGHTING);
		}
		else
		{
			glEnable(GL_LIGHTING);
		}

		if(mesh->mColors[0] != NULL)
		{
			glEnable(GL_COLOR_MATERIAL);
		}
		else
		{
			glDisable(GL_COLOR_MATERIAL);
		}



		for (t = 0; t < mesh->mNumFaces; ++t) {
			const struct aiFace* face = &mesh->mFaces[t];
			GLenum face_mode;

			switch(face->mNumIndices)
			{
				case 1: face_mode = GL_POINTS; break;
				case 2: face_mode = GL_LINES; break;
				case 3: face_mode = GL_TRIANGLES; break;
				default: face_mode = GL_POLYGON; break;
			}

			glBegin(face_mode);

			for(i = 0; i < face->mNumIndices; i++)		// go through all vertices in face
			{
				int vertexIndex = face->mIndices[i];	// get group index for current index
				if(mesh->mColors[0] != NULL)
					Color4f(&mesh->mColors[0][vertexIndex]);
				if(mesh->mNormals != NULL)

					if(mesh->HasTextureCoords(0))		//HasTextureCoords(texture_coordinates_set)
					{
						glTexCoord2f(mesh->mTextureCoords[0][vertexIndex].x, 1 - mesh->mTextureCoords[0][vertexIndex].y); //mTextureCoords[channel][vertex]
					}

					glNormal3fv(&mesh->mNormals[vertexIndex].x);
					glVertex3fv(&mesh->mVertices[vertexIndex].x);
			}

			glEnd();

		}

	}


	// draw all children
	for (n = 0; n < nd->mNumChildren; ++n)
	{
		recursive_render(sc, nd->mChildren[n], scale);
	}

	glPopMatrix();
}
Example #9
0
void render(void)
{
static GLint iFrames = 0;
static GLfloat fps = 0.0f, DeltaT;
static char cBuffer[64];
struct timeval tv;
GLuint model_id;

	// Update timer
	gettimeofday(&tv, NULL);
	etime = (double)tv.tv_sec + tv.tv_usec / 1000000.0f;

	dt = etime - t0;
	t0 = etime;

	/*
	 * Make the shadow pass
	 *
	 */

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, FBO );

	glPushMatrix();

		//Compute light position
		sinE = sinf(eLit);
		cosE = cosf(eLit);
		sinA = sinf(aLit);
		cosA = cosf(aLit);

		lightPos[0] = lightRadius * cosE * sinA;
		lightPos[1] = lightRadius * sinE;
		lightPos[2] = lightRadius * cosE * cosA;
		lightPos[3] = 1.0f;

		//Set light position
		glLightfv(GL_LIGHT0, GL_POSITION, lightPos);

		//Set up camera to light location
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective( 70.0f, 1.0f, 75.0f, 350.0f );
		glGetDoublev(GL_PROJECTION_MATRIX, lightProjection );
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		gluLookAt( lightPos[0], lightPos[1], lightPos[2],
			0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f );
		glGetDoublev(GL_MODELVIEW_MATRIX, lightModelview );
		glViewport( 0, 0, shadow_sz, shadow_sz );

		glClear(GL_DEPTH_BUFFER_BIT);

		glEnable(GL_POLYGON_OFFSET_FILL);
		glShadeModel(GL_FLAT);

		//Rotate scene, if required
		glRotatef(xRot, 1.0f, 0.0f, 0.0f);
		glRotatef(yRot, 0.0f, 1.0f, 0.0f);

		//Disable shaders
		glUseProgramObjectARB(0);
		glDisable(GL_VERTEX_PROGRAM_ARB);
		glDisable(GL_FRAGMENT_PROGRAM_ARB);

		// Draw dynamic objects
		for (model_id = 0; model_id < NUM_MODELS; model_id++ )
		{
			//Update the kinematic's state
			UpdateMD2(md2_model[model_id], dt);
	
			//Animate the MD2 models
			AnimateMD2(md2_model[model_id], dt);
			
			//Draw the geometry
			glPushMatrix();
				glTranslatef(	md2_model[model_id]->position.x,
						md2_model[model_id]->position.y,
						md2_model[model_id]->position.z );
				glRotatef( md2_model[model_id]->rotation, 0.0f, 1.0f, 0.0f );
				DrawMD2(md2_model[model_id]);
			glPopMatrix();
		}

	glPopMatrix();

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 );

	/*
	 * And now the normal pass
	 *
	 */

	//Back to normal settings
	glDisable(GL_POLYGON_OFFSET_FILL);
	glShadeModel(GL_SMOOTH);
	change_size( width, height );

	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();

		//Set up camera location and parameters
		setup_camera((float)dt);

		//Retrieve modelview matrix and invert it
		glGetDoublev(GL_MODELVIEW_MATRIX, cameraModelview );
		FastInvert4( cameraModelview, cameraModelviewInverse );

		//Set up depth texture
		glActiveTexture(GL_TEXTURE2);
		glBindTexture(GL_TEXTURE_2D, shadow_tx);

		//Set up texture matrix for shadow map projection
		glMatrixMode(GL_TEXTURE);
		glLoadIdentity();
		glTranslatef(0.5f, 0.5f, 0.5f);
		glScalef(0.5f, 0.5f, 0.5f);
		glMultMatrixd(lightProjection);
		glMultMatrixd(lightModelview);
		glMultMatrixd(cameraModelviewInverse);
		glMatrixMode(GL_MODELVIEW);

		//Rotate scene
		glRotatef(xRot, 1.0f, 0.0f, 0.0f);
		glRotatef(yRot, 0.0f, 1.0f, 0.0f);

		//Re-enable shaders
		glEnable(GL_VERTEX_PROGRAM_ARB);
		glEnable(GL_FRAGMENT_PROGRAM_ARB);

		if (GLSLshader)
			glUseProgramObjectARB(progObj);
		else
			glUseProgramObjectARB(0);

		//Floor

		//Color
		glColor3f(0.64f, 0.63f, 0.65f);

		//Set textures
		glActiveTexture(GL_TEXTURE0);	//Diffuse map
		glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-2]);

		glActiveTexture(GL_TEXTURE1);	//Normal map
		glBindTexture(GL_TEXTURE_2D, texture_id[NUM_TEXTURES-1]);

		//Set Tangent vector
		glVertexAttrib3fv( tangent, floorT );

		//Set Binormal vector
		glVertexAttrib3fv( binormal, floorB );

		//Set Normal vector
		glNormal3fv( floorN );

		//Call Display List to draw
		glCallList(FList);

		// Draw dynamic objects
		for (model_id = 0; model_id < NUM_MODELS; model_id++ )
		{
			//Set color
			glColor3f(	md2_model[model_id]->color.x,
					md2_model[model_id]->color.y,
					md2_model[model_id]->color.z );
	
			//Set texture
			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id]);
			glActiveTexture(GL_TEXTURE1);
			glBindTexture(GL_TEXTURE_2D, texture_id[2*model_id+1]);
	
			//Draw the geometry
			glPushMatrix();
				glTranslatef(	md2_model[model_id]->position.x,
						md2_model[model_id]->position.y,
						md2_model[model_id]->position.z );
				glRotatef( md2_model[model_id]->rotation, 0.0f, 1.0f, 0.0f );
				DrawMD2(md2_model[model_id]);
			glPopMatrix();
		}

	glPopMatrix();

	iFrames++;
	DeltaT = (GLfloat)(etime-t1);
	if( DeltaT >= Timed )
	{
		fps = (GLfloat)(iFrames)/DeltaT;
		fps_count++;
		fps_mean = ((fps_count - 1.0f) * fps_mean + fps ) / fps_count;

		iFrames = 0;
		t1 = etime;

		sprintf(cBuffer,"FPS: %.1f Mean FPS: %.1f Poly Scale: %.1f Bias: %.1f", fps, fps_mean, scalePoly, biasPoly);
	}
	if (print_fps)
	{
		if (windowpos)
		{
			glColor3f(1.0f, 1.0f, 1.0f);
			glPushAttrib(GL_LIST_BIT);
				glListBase(fps_font - ' ');
				glWindowPos2i(0,2);
				glCallLists(strlen(cBuffer), GL_UNSIGNED_BYTE, cBuffer);
			glPopAttrib();
		}
		if( iFrames == 0 )
			printf("FPS: %.1f Mean FPS: %.1f\n", fps, fps_mean);
	}
	lCam = 0.0f;
	vCam = 0.0f;
	dCam = 0.0f;
}
Example #10
0
File: LAB7.cpp Project: ntlone/Lab7
void DrawInsidePhyramid()
{
	CVector vertices[11] = {
		{ 0.0f, 0.0f, 9.9f }, // Góra figóry
		{ 0.0f, 1.9f, 0.0f }, //                1
		{ 1.4f, 1.4f, 0.0f }, //           10        2
		{ 1.9f, 0.0f, 0.0f }, //          9     0      3
		{ 1.6f, -1.1f, 0.0f }, //          8          4
		{ 0.9f, -1.4f, 0.0f }, //             7    5
		{ 0.0f, -1.9f, 0.0f }, //                6
		{ -0.9f, -1.4f, 0.0f }, //
		{ -1.6f, -1.1f, 0.0f }, //
		{ -1.9f, 0.0f, 0.0f }, //
		{ -1.4f, 1.4f, 0.0f }, //
	};

	CVector normals[11] = {
		{ 0.0f, 1.0f, 0.0f },
		GetNormalFromPoints(vertices[1], vertices[0], vertices[2]),
		GetNormalFromPoints(vertices[2], vertices[0], vertices[3]),
		GetNormalFromPoints(vertices[3], vertices[0], vertices[4]),
		GetNormalFromPoints(vertices[4], vertices[0], vertices[5]),
		GetNormalFromPoints(vertices[5], vertices[0], vertices[6]),
		GetNormalFromPoints(vertices[6], vertices[0], vertices[7]),
		GetNormalFromPoints(vertices[7], vertices[0], vertices[8]),
		GetNormalFromPoints(vertices[8], vertices[0], vertices[9]),
		GetNormalFromPoints(vertices[9], vertices[0], vertices[10]),
		GetNormalFromPoints(vertices[10], vertices[0], vertices[1])
	};

	glBegin(GL_TRIANGLES);

	glColor3f(1.0, 0.0, 0.0);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[1].vectors);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[2].vectors);

	glColor3f(0.0, 1.0, 0.0);
	glNormal3fv(normals[2].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[2].vectors);
	glVertex3fv(vertices[2].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[3].vectors);

	glColor3f(0.0, 0.0, 1.0);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[3].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[4].vectors);

	glColor3f(1.0, 1.0, 0.0);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[4].vectors);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[5].vectors);

	glColor3f(1.0, 0.0, 1.0);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[5].vectors);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[6].vectors);

	glColor3f(0.0, 1.0, 1.0);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[6].vectors);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[7].vectors);

	glColor3f(1.0, 1.0, 1.0);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[7].vectors);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[8].vectors);

	glColor3f(1.0, 0.5, 0.0);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[8].vectors);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[9].vectors);

	glColor3f(0.5, 1.0, 0.0);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[9].vectors);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[10].vectors);

	glColor3f(0.5, 1.0, 1.0);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[10].vectors);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[1].vectors);

	glEnd();
}
Example #11
0
void Plane::draw(std::shared_ptr< FrameEventArgs > args) {
	auto scene = this->getGameObjectSet().lock()->getOwner();
	auto camera = scene->getActiveCamera();
	auto cameraTransform = camera->getComponents()->getSingleByClass<Transform>();

	this->recalculateForPositionAndTime(cameraTransform->getPosition(), args->getTotalSeconds());

	if(this->axesVisible) {
		drawAxes(50);
	}

	Vertex* base = this->vertices.get();
	Vertex* v1 = 0;
	Vertex* v2 = 0;
	Vertex* v3 = 0;
	Vertex* v4 = 0;

		
	this->setupMaterial();

	glBegin(GL_TRIANGLES);

	for(int xsegment = 0; xsegment < this->segments; ++xsegment) {
		for(int zsegment = 0; zsegment < this->segments; ++zsegment) {
			v1 = base + this->vertexIndex(xsegment, zsegment);
			v2 = base + this->vertexIndex(xsegment + 1, zsegment);
			v3 = base + this->vertexIndex(xsegment + 1, zsegment + 1);
			v4 = base + this->vertexIndex(xsegment, zsegment + 1);

			// These normals are here only to show lighting effect, they're not proper normals

			glNormal3fv(v1->normal);
			glTexCoord2fv(v1->texcoord);
			glVertex3fv(v1->position);

			glNormal3fv(v2->normal);
			glTexCoord2fv(v2->texcoord);
			glVertex3fv(v2->position);

			glNormal3fv(v4->normal);
			glTexCoord2fv(v4->texcoord);
			glVertex3fv(v4->position);


			glNormal3fv(v2->normal);
			glTexCoord2fv(v2->texcoord);
			glVertex3fv(v2->position);

			glNormal3fv(v3->normal);
			glTexCoord2fv(v3->texcoord);
			glVertex3fv(v3->position);

			glNormal3fv(v4->normal);
			glTexCoord2fv(v4->texcoord);
			glVertex3fv(v4->position);
		}
	}
		
	glEnd();
	glDisable(GL_TEXTURE_2D);

	if(this->normalsVisible) {
		this->drawNormals();
	}
}
Example #12
0
File: LAB7.cpp Project: ntlone/Lab7
void DrawOutsidePhyramid()
{
	CVector vertices[11] = {
		{ 0.0f, 0.0f, 10.0f }, // Góra figóry
		{ 0.0f, 2.0f, 0.0f }, //                1
		{ 1.5f, 1.5f, 0.0f }, //           10        2
		{ 2.0f, 0.0f, 0.0f }, //          9     0      3
		{ 1.7f, -1.2f, 0.0f }, //          8          4
		{ 1.0f, -1.5f, 0.0f }, //            7      5
		{ 0.0f, -2.0f, 0.0f }, //               6
		{ -1.0f, -1.5f, 0.0f }, //
		{ -1.7f, -1.2f, 0.0f }, //
		{ -2.0f, 0.0f, 0.0f }, //
		{ -1.5f, 1.5f, 0.0f }, //
	};

	CVector normals[11] = {
		{ 0.0f, -1.0f, 0.0f },
		GetNormalFromPoints(vertices[2], vertices[0], vertices[1]),
		GetNormalFromPoints(vertices[3], vertices[0], vertices[2]),
		GetNormalFromPoints(vertices[4], vertices[0], vertices[3]),
		GetNormalFromPoints(vertices[5], vertices[0], vertices[4]),
		GetNormalFromPoints(vertices[6], vertices[0], vertices[5]),
		GetNormalFromPoints(vertices[7], vertices[0], vertices[6]),
		GetNormalFromPoints(vertices[8], vertices[0], vertices[7]),
		GetNormalFromPoints(vertices[9], vertices[0], vertices[8]),
		GetNormalFromPoints(vertices[10], vertices[0], vertices[9]),
		GetNormalFromPoints(vertices[1], vertices[0], vertices[10])
	};

	glBegin(GL_TRIANGLES);

	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[1].vectors);
	glNormal3fv(normals[1].vectors);
	glVertex3fv(vertices[2].vectors);

	glNormal3fv(normals[2].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[2].vectors);
	glVertex3fv(vertices[2].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[3].vectors);

	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[3].vectors);
	glNormal3fv(normals[3].vectors);
	glVertex3fv(vertices[4].vectors);

	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[4].vectors);
	glNormal3fv(normals[4].vectors);
	glVertex3fv(vertices[5].vectors);

	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[5].vectors);
	glNormal3fv(normals[5].vectors);
	glVertex3fv(vertices[6].vectors);

	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[6].vectors);
	glNormal3fv(normals[6].vectors);
	glVertex3fv(vertices[7].vectors);

	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[7].vectors);
	glNormal3fv(normals[7].vectors);
	glVertex3fv(vertices[8].vectors);

	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[8].vectors);
	glNormal3fv(normals[8].vectors);
	glVertex3fv(vertices[9].vectors);

	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[9].vectors);
	glNormal3fv(normals[9].vectors);
	glVertex3fv(vertices[10].vectors);

	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[0].vectors);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[10].vectors);
	glNormal3fv(normals[10].vectors);
	glVertex3fv(vertices[1].vectors);

	glEnd();

	glBegin(GL_POLYGON);

	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[1].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[2].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[3].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[4].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[5].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[6].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[7].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[8].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[9].vectors);
	glNormal3fv(normals[0].vectors);
	glVertex3fv(vertices[10].vectors);

	glEnd();
}
Example #13
0
static void GLAPIENTRY normalCallback(GLfloat *normal)
{
   glNormal3fv(normal);  /*  resubmit rendering directive  */
   printf ("glNormal3f (%5.3f, %5.3f, %5.3f)\n", 
           normal[0], normal[1], normal[2]);
}
Example #14
0
GLvoid swglmDraw(GLMmodel* model)
{
	GLfloat *n1, *n2, *n3;
	GLfloat *v1, *v2, *v3;

	//get current color
	GLdouble col[4];
	glGetDoublev(GL_CURRENT_COLOR, col);

    for (unsigned int i = 0; i < model->numtriangles; i++) {

        GLMtriangle* triangle = &(model->triangles[i]);
        //GLfloat* vertices = &(model->vertices[i]);

        n1 = &model->normals[3 * triangle->nindices[0]];
        v1 = &model->vertices[3 * triangle->vindices[0]];
        n2 = &model->normals[3 * triangle->nindices[1]];
        v2 = &model->vertices[3 * triangle->vindices[1]];
		n3 = &model->normals[3 * triangle->nindices[2]];
        v3 = &model->vertices[3 * triangle->vindices[2]];


/*
        if(i<20){

        std::cout<< model->numtriangles <<'\n';
        std::cout<< model->numvertices <<'\n';
        std::cout<< triangle->vindices[0] <<" "<< triangle->vindices[1] <<" "<< triangle->vindices[2] <<'\n';
        std::cout<< v1[0] <<" "<< v1[1] <<" "<< v1[2] <<'\n';
        //std::cout<< model->vertices[3 * triangle->vindices[0]+ 0] <<" "<< model->vertices[3 * triangle->vindices[0] + 1] <<" "<< model->vertices[3 * triangle->vindices[0] + 2] <<'\n';

        std::cout<< n1[0] <<" "<< n1[1] <<" "<< n1[2] <<'\n';

        std::cout<< col[0] <<" "<< col[1] <<" "<< col[2] <<'\n';
        if(i==19){
                std::cout<<"oooooooooooooooooooo"<<'\n';
            }
        }
*/

        for(int i=0;i<3;i++){
            n1[i] = n1[i] + 0.1;
            n2[i] = n2[i] + 0.1;
            n3[i] = n3[i] + 0.1;
        }

        glBegin(GL_TRIANGLES);
        for (int i = 0; i < model->numtriangles; i++) {


            glNormal3fv(n1);
            glVertex3fv(v1);

            glNormal3fv(n2);
            glVertex3fv(v2);

            glNormal3fv(n3);
            glVertex3fv(v3);

        }
        glEnd();


    }


}
Example #15
0
// Doc in parent
void
SoVRMLIndexedFaceSet::GLRender(SoGLRenderAction * action)
{
  if (this->coordIndex.getNum() < 3 || this->coord.getValue() == NULL) return;
  SoState * state = action->getState();

  state->push();
  // update state with coordinates, normals and texture information
  SoVRMLVertexShape::GLRender(action);

  if (!this->shouldGLRender(action)) { 
    state->pop();
    return;
  }

  this->setupShapeHints(state, this->ccw.getValue(), this->solid.getValue());

  Binding mbind = this->findMaterialBinding(state);
  Binding nbind = this->findNormalBinding(state);

  const SoCoordinateElement * coords;
  const SbVec3f * normals;
  const int32_t * cindices;
  int numindices;
  const int32_t * nindices;
  const int32_t * tindices;
  const int32_t * mindices;
  SbBool doTextures;
  SbBool normalCacheUsed;
  SoMaterialBundle mb(action);
  SoTextureCoordinateBundle tb(action, TRUE, FALSE);
  doTextures = tb.needCoordinates();

  SbBool sendNormals = !mb.isColorOnly() || tb.isFunction();

  this->getVertexData(state, coords, normals, cindices,
                      nindices, tindices, mindices, numindices,
                      sendNormals, normalCacheUsed);

  if (!sendNormals) {
    nbind = OVERALL;
    normals = NULL;
    nindices = NULL;
  }
  else if (nbind == OVERALL) {
    if (normals) glNormal3fv(normals[0].getValue());
    else glNormal3f(0.0f, 0.0f, 1.0f);
  }
  else if (normalCacheUsed && nbind == PER_VERTEX) {
    nbind = PER_VERTEX_INDEXED;
  }
  else if (normalCacheUsed && nbind == PER_FACE_INDEXED) {
    nbind = PER_FACE;
  }

  if (mbind == PER_VERTEX) {
    mbind = PER_VERTEX_INDEXED;
    mindices = cindices;
  }
  if (nbind == PER_VERTEX) {
    nbind = PER_VERTEX_INDEXED;
    nindices = cindices;
  }

  Binding tbind = NONE;
  if (doTextures) {
    if (tb.isFunction() && !tb.needIndices()) {
      tbind = NONE;
      tindices = NULL;
    }
    else {
      tbind = PER_VERTEX_INDEXED;
      if (tindices == NULL) tindices = cindices;
    }
  }
  SbBool convexcacheused = FALSE;

  if (this->useConvexCache(action, normals, nindices, normalCacheUsed)) {
    cindices = PRIVATE(this)->convexCache->getCoordIndices();
    numindices = PRIVATE(this)->convexCache->getNumCoordIndices();
    mindices = PRIVATE(this)->convexCache->getMaterialIndices();
    nindices = PRIVATE(this)->convexCache->getNormalIndices();
    tindices = PRIVATE(this)->convexCache->getTexIndices();

    if (mbind == PER_VERTEX) mbind = PER_VERTEX_INDEXED;
    else if (mbind == PER_FACE) mbind = PER_FACE_INDEXED;
    if (nbind == PER_VERTEX) nbind = PER_VERTEX_INDEXED;
    else if (nbind == PER_FACE) nbind = PER_FACE_INDEXED;

    if (tbind != NONE) tbind = PER_VERTEX_INDEXED;
    convexcacheused = TRUE;
  }

  mb.sendFirst(); // make sure we have the correct material

  SoGLLazyElement * lelem = NULL;
  const uint32_t contextid = action->getCacheContext();

  SbBool dova = 
    SoVBO::shouldRenderAsVertexArrays(state, contextid, numindices) &&
    !convexcacheused && !normalCacheUsed &&
    ((nbind == OVERALL) || ((nbind == PER_VERTEX_INDEXED) && ((nindices == cindices) || (nindices == NULL)))) &&
    ((tbind == NONE && !tb.needCoordinates()) || 
     ((tbind == PER_VERTEX_INDEXED) && ((tindices == cindices) || (tindices == NULL)))) &&
    ((mbind == NONE) || ((mbind == PER_VERTEX_INDEXED) && ((mindices == cindices) || (mindices == NULL)))) &&
    SoGLDriverDatabase::isSupported(sogl_glue_instance(state), SO_GL_VERTEX_ARRAY);

  const SoGLVBOElement * vboelem = SoGLVBOElement::getInstance(state);
  SoVBO * colorvbo = NULL;

  if (dova && (mbind != OVERALL)) {
    dova = FALSE;
    if ((mbind == PER_VERTEX_INDEXED) && ((mindices == cindices) || (mindices == NULL))) {
      lelem = (SoGLLazyElement*) SoLazyElement::getInstance(state);
      colorvbo = vboelem->getColorVBO();
      if (colorvbo) dova = TRUE;
      else {
        // we might be able to do VA-rendering, but need to check the
        // diffuse color type first.
        if (!lelem->isPacked() && lelem->getNumTransparencies() <= 1) {
          dova = TRUE;
        }
      }
    }
  }
  SbBool didrenderasvbo = FALSE;
  if (dova) {
    SbBool dovbo = this->startVertexArray(action,
                                          coords,
                                          (nbind != OVERALL) ? normals : NULL,
                                          doTextures,
                                          mbind != OVERALL);
    didrenderasvbo = dovbo;
    LOCK_VAINDEXER(this);
    if (PRIVATE(this)->vaindexer == NULL) {
      SoVertexArrayIndexer * indexer = new SoVertexArrayIndexer;
      int i = 0;
      while (i < numindices) {
        int cnt = 0;
        while (i + cnt < numindices && cindices[i+cnt] >= 0) cnt++;
        
        switch (cnt) {
        case 3:
          indexer->addTriangle(cindices[i],cindices[i+1], cindices[i+2]);
          break;
        case 4:
          indexer->addQuad(cindices[i],cindices[i+1],cindices[i+2],cindices[i+3]);
          break;
        default:
          if (cnt > 4) {
            indexer->beginTarget(GL_POLYGON);
            for (int j = 0; j < cnt; j++) {
              indexer->targetVertex(GL_POLYGON, cindices[i+j]);
            }
            indexer->endTarget(GL_POLYGON);
          }
        }
        i += cnt + 1;
      }
      indexer->close();
      if (indexer->getNumVertices()) {
        PRIVATE(this)->vaindexer = indexer;
      }
      else {
        delete indexer;
      }
#if 0
      fprintf(stderr,"XXX: create VRML VertexArrayIndexer: %d\n", indexer->getNumVertices());
#endif
    }

    if (PRIVATE(this)->vaindexer) {
      PRIVATE(this)->vaindexer->render(sogl_glue_instance(state), dovbo, contextid);
    }
    UNLOCK_VAINDEXER(this);
    this->finishVertexArray(action,
                            dovbo,
                            (nbind != OVERALL),
                            doTextures,
                            mbind != OVERALL);
  }
  else {
    SoVertexAttributeBundle vab(action, TRUE);
    SbBool doattribs = vab.doAttributes();

    SoVertexAttributeBindingElement::Binding attribbind = 
      SoVertexAttributeBindingElement::get(state);

    if (!doattribs) { 
      // for overall attribute binding we check for doattribs before
      // sending anything in SoGL::FaceSet::GLRender
      attribbind = SoVertexAttributeBindingElement::OVERALL;
    }

    sogl_render_faceset((SoGLCoordinateElement *)coords,
                        cindices,
                        numindices,
                        normals,
                        nindices,
                        &mb,
                        mindices,
                        &tb,
                        tindices,
                        &vab,
                        (int)nbind,
                        (int)mbind,
                        (int)attribbind,
                        doTextures ? 1 : 0,
                        doattribs ? 1 : 0);

  }
  if (normalCacheUsed) {
    this->readUnlockNormalCache();
  }

  if (convexcacheused) {
    PRIVATE(this)->readUnlockConvexCache();
  }

  // send approx number of triangles for autocache handling
  sogl_autocache_update(state, this->coordIndex.getNum() / 4, didrenderasvbo);

  state->pop();
}
Example #16
0
static void
RandomPrimitive(void)
{
   int i;
   int len = MinVertexCount + RandomInt(MaxVertexCount - MinVertexCount);

   Vprim = RandomInt(10);

   glBegin(Vprim);
   Vbuffer[Vcount].type = BEGIN;
   Vbuffer[Vcount].v[0] = Vprim;
   Vcount++;

   for (i = 0; i < len; i++) {
      Vbuffer[Vcount].v[0] = RandomFloat(-3, 3);
      Vbuffer[Vcount].v[1] = RandomFloat(-3, 3);
      Vbuffer[Vcount].v[2] = RandomFloat(-3, 3);
      Vbuffer[Vcount].v[3] = RandomFloat(-3, 3);
      int k = RandomInt(9);
      switch (k) {
      case 0:
         glVertex2fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = VERTEX2;
         break;
      case 1:
         glVertex3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = VERTEX3;
         break;
      case 2:
         glVertex4fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = VERTEX4;
         break;
      case 3:
         glColor3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = COLOR3;
         break;
      case 4:
         glColor4fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = COLOR4;
         break;
      case 5:
         glTexCoord2fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = TEX2;
         break;
      case 6:
         glTexCoord3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = TEX3;
         break;
      case 7:
         glTexCoord4fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = TEX4;
         break;
      case 8:
         glSecondaryColor3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = SECCOLOR3;
         break;
      case 9:
         glNormal3fv(Vbuffer[Vcount].v);
         Vbuffer[Vcount].type = NORMAL3;
         break;
      default:
         abort();
      }
      Vcount++;

      if (Vcount >= BufferSize - 2) {
         /* reset */
         Vcount = 0;
      }
   }

   Vbuffer[Vcount++].type = END;

   glEnd();
}
Example #17
0
void draw_skybox(void){
  int i;

/* stuff min and max grid data into a more convenient form 
  assuming the following grid numbering scheme

       5-------6
     / |      /| 
   /   |     / | 
  4 -------7   |
  |    |   |   |  
  Z    1---|---2
  |  Y     |  /
  |/       |/
  0--X-----3     

  */
  float points[]={
    0.0,0.0,0.0,
    0.0,1.0,0.0,
    1.0,1.0,0.0,
    1.0,0.0,0.0,
    0.0,0.0,1.0,
    0.0,1.0,1.0,
    1.0,1.0,1.0,
    1.0,0.0,1.0
  };
  float normals[]={
     0.0,-1.0, 0.0,
    -1.0, 0.0, 0.0,
     0.0, 1.0, 0.0,
     1.0, 0.0, 0.0,
     0.0, 0.0, 1.0,
     0.0, 0.0,-1.0
  };
  int faces[]={
    1,2,6,5,
    2,3,7,6,
    3,0,4,7,
    0,1,5,4,
    0,3,2,1,
    5,6,7,4
  };
  float *xyz;
  float *normal;
  int *faceptr;

  float increment=0.0;

  for(i=0;i<8;i++){
    xyz = points + 3*i;
    xyz[0] = 3.0*(xyz[0]-0.5) + camera_current->eye[0];
    xyz[1] = 3.0*(xyz[1]-0.5) + camera_current->eye[1];
    xyz[2] = 3.0*(xyz[2]-0.5+increment) + camera_current->eye[2];
  }

  glDisable(GL_BLEND);
  glDepthMask(GL_FALSE);
  glDisable(GL_DEPTH_TEST);
  glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
  glEnable(GL_TEXTURE_2D);

  for(i=0;i<6;i++){
  
    if(skyboxinfo->face[i].file==NULL)continue;

    glBindTexture(GL_TEXTURE_2D,skyboxinfo->face[i].name);
    glBegin(GL_QUADS);
    
    normal = normals + 3*i;
    faceptr = faces + 4*i;

    glNormal3fv(normal);
    glTexCoord2f(0.0,0.0);
    xyz = points + 3*faceptr[0];
    glVertex3fv(xyz);

    glTexCoord2f(1.0,0.0);
    xyz = points + 3*faceptr[1];
    glVertex3fv(xyz);

    glTexCoord2f(1.0,1.0);
    xyz = points + 3*faceptr[2];
    glVertex3fv(xyz);

    glTexCoord2f(0.0,1.0);
    xyz = points + 3*faceptr[3];
    glVertex3fv(xyz);
    glEnd();

  }
  glDisable(GL_TEXTURE_2D);
  glEnable(GL_DEPTH_TEST);
  glDepthMask(GL_TRUE);
  glEnable(GL_BLEND);
  draw_floor();
}
Example #18
0
static void
myElbow(ModeInfo * mi, int bolted)
{
	pipesstruct *pp = &pipes[MI_SCREEN(mi)];
    Bool        wire = MI_IS_WIREFRAME(mi);

    int nsides = (wire ? 6 : 25);
    int rings  = nsides;
#define r one_third
#define R one_third

	int         i, j;
	GLfloat     p0[3], p1[3], p2[3], p3[3];
	GLfloat     n0[3], n1[3], n2[3], n3[3];
	GLfloat     COSphi, COSphi1, COStheta, COStheta1;
	GLfloat     _SINtheta, _SINtheta1;

	for (i = 0; i <= rings / 4; i++) {
		GLfloat     theta, theta1;

		theta = (GLfloat) i *2.0 * M_PI / rings;

		theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
		for (j = 0; j < nsides; j++) {
			GLfloat     phi, phi1;

			phi = (GLfloat) j *2.0 * M_PI / nsides;

			phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;

			p0[0] = (COStheta = cos(theta)) * (R + r * (COSphi = cos(phi)));
			p0[1] = (_SINtheta = -sin(theta)) * (R + r * COSphi);

			p1[0] = (COStheta1 = cos(theta1)) * (R + r * COSphi);
			p1[1] = (_SINtheta1 = -sin(theta1)) * (R + r * COSphi);

			p2[0] = COStheta1 * (R + r * (COSphi1 = cos(phi1)));
			p2[1] = _SINtheta1 * (R + r * COSphi1);

			p3[0] = COStheta * (R + r * COSphi1);
			p3[1] = _SINtheta * (R + r * COSphi1);

			n0[0] = COStheta * COSphi;
			n0[1] = _SINtheta * COSphi;

			n1[0] = COStheta1 * COSphi;
			n1[1] = _SINtheta1 * COSphi;

			n2[0] = COStheta1 * COSphi1;
			n2[1] = _SINtheta1 * COSphi1;

			n3[0] = COStheta * COSphi1;
			n3[1] = _SINtheta * COSphi1;

			p0[2] = p1[2] = r * (n0[2] = n1[2] = sin(phi));
			p2[2] = p3[2] = r * (n2[2] = n3[2] = sin(phi1));

			glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
			glNormal3fv(n3);
			glVertex3fv(p3);
			glNormal3fv(n2);
			glVertex3fv(p2);
			glNormal3fv(n1);
			glVertex3fv(p1);
			glNormal3fv(n0);
			glVertex3fv(p0);
            mi->polygon_count++;
			glEnd();
		}
	}

	if (factory > 0 && bolted) {
		/* Bolt the elbow onto the pipe system */
		glFrontFace(GL_CW);
		glPushMatrix();
		glRotatef(90.0, 0.0, 0.0, -1.0);
		glRotatef(90.0, 0.0, 1.0, 0.0);
		glTranslatef(0.0, one_third, one_third);
		glCallList(pp->elbowcoins);
        mi->polygon_count += LWO_ElbowCoins.num_pnts/3;
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
		glCallList(pp->elbowbolts);
        mi->polygon_count += LWO_ElbowBolts.num_pnts/3;
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
		glPopMatrix();
		glFrontFace(GL_CCW);
	}
#undef r
#undef R
#undef nsides
#undef rings
}
Action::ResultE QuadParticleSystemDrawer::draw(DrawEnv *pEnv, ParticleSystemUnrecPtr System, const MFUInt32& Sort)
{
    bool isSorted(Sort.size() > 0);
    UInt32 NumParticles;
    if(isSorted)
    {
        NumParticles = Sort.size();
    }
    else
    {
        NumParticles = System->getNumParticles();
    }
    Pnt3f P1,P2,P3,P4;
    UInt32 Index;

    //Calculate the CameraToObject basis
    Matrix WorldToObject(pEnv->getObjectToWorld()); 
    WorldToObject.invert();

    Matrix CameraToObject(pEnv->getCameraToWorld()); 
    CameraToObject.mult(WorldToObject);

    glBegin(GL_QUADS);
        for(UInt32 i(0); i<NumParticles;++i)
        {
            if(isSorted)
            {
                Index = Sort[i];
            }
            else
            {
                Index = i;
            }
            //Loop through all particles
            //Get The Normal of the Particle
            Vec3f Normal = getQuadNormal(pEnv, System, Index, CameraToObject);


            //Calculate the Binormal as the cross between Normal and Up
            Vec3f Binormal = getQuadUpDir(pEnv,  System, Index, CameraToObject).cross(Normal);

            //Get the Up Direction of the Particle
            Vec3f Up = Normal.cross(Binormal);

            //Determine Local Space of the Particle
            //This is where error occurs
            Pnt3f Position = System->getPosition(Index);

            //Determine the Width and Height of the quad
            Real32 Width = System->getSize(Index).x()*getQuadSizeScaling().x(),Height =System->getSize(Index).y()*getQuadSizeScaling().y();

            //Calculate Quads positions
            P1 = Position + (Width/2.0f)*Binormal + (Height/2.0f)*Up;
            P2 = Position + (Width/2.0f)*Binormal - (Height/2.0f)*Up;
            P3 = Position - (Width/2.0f)*Binormal - (Height/2.0f)*Up;
            P4 = Position - (Width/2.0f)*Binormal + (Height/2.0f)*Up;

            //Draw the Quad
            glNormal3fv(Normal.getValues());

            glColor4fv(System->getColor(Index).getValuesRGBA());
            glTexCoord2f(1.0, 1.0);
            glVertex3fv(P1.getValues());


            glTexCoord2f(0.0, 1.0);
            glVertex3fv(P4.getValues());


            glTexCoord2f(0.0, 0.0);
            glVertex3fv(P3.getValues());

            glTexCoord2f(1.0, 0.0);
            glVertex3fv(P2.getValues());
        }
        glColor4f(1.0f,1.0f,1.0f,1.0f);
    glEnd();

    //Generate a local space for the particle
    return Action::Continue;
}
void S3D_MESH::openGL_Render()
{
    //DBG( printf( "openGL_Render" ) );
    bool useMaterial = g_Parm_3D_Visu.GetFlag( FL_RENDER_MATERIAL );
    bool smoothShapes = g_Parm_3D_Visu.IsRealisticMode()
                        && g_Parm_3D_Visu.GetFlag( FL_RENDER_SMOOTH );

    if( m_Materials )
    {
        m_Materials->SetOpenGLMaterial( 0, useMaterial );
    }

    if( m_CoordIndex.size() == 0)
    {

        return;
    }

    glPushMatrix();
    glTranslatef( m_translation.x, m_translation.y, m_translation.z );
    glRotatef( m_rotation[3], m_rotation[0], m_rotation[1], m_rotation[2] );
    glScalef( m_scale.x, m_scale.y, m_scale.z );

    std::vector< glm::vec3 > normals;

    calcPointNormalized();
    calcPerFaceNormals();

    if( m_PerVertexNormalsNormalized.size() == 0 )
    {
        if( smoothShapes )
        {
            calcPerPointNormals();
        }
    }

    for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )
    {
        if( m_MaterialIndex.size() > 1 )
        {
            if( m_Materials )
            {
                m_Materials->SetOpenGLMaterial( m_MaterialIndex[idx], useMaterial );
            }
        }


        switch( m_CoordIndex[idx].size() )
        {
        case 3:     glBegin( GL_TRIANGLES );break;
        case 4:     glBegin( GL_QUADS );    break;
        default:    glBegin( GL_POLYGON );  break;
        }


        if( m_PerVertexNormalsNormalized.size() > 0 )
        {
            for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ )
            {
                glm::vec3 normal = m_PerVertexNormalsNormalized[m_NormalIndex[idx][ii]];
                glNormal3fv( &normal.x );

                glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
                glVertex3fv( &point.x );
            }
        }
        else if( smoothShapes )
        {
            std::vector< glm::vec3 > normals_list;
            normals_list = m_PerFaceVertexNormals[idx];

            for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ )
            {
                glm::vec3 normal = normals_list[ii];
                glNormal3fv( &normal.x );

                glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
                glVertex3fv( &point.x );
            }
        }
        else
        {
            // Flat
            glm::vec3 normal = m_PerFaceNormalsNormalized[idx];

            for( unsigned int ii = 0; ii < m_CoordIndex[idx].size(); ii++ )
            {
                glNormal3fv( &normal.x );

                glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
                glVertex3fv( &point.x );
            }
        }

        glEnd();
    }

    glPopMatrix();
}
Example #21
0
void draw_vertex(gint index, vertex *hf) {
	glNormal3fv(&hf[index].nx);
	glVertex3fv(&hf[index].x);
}
Example #22
0
void Mesh::render(int renderMode, int glMode){
	int group_name = 0;
	int currentID = 0;
	
	glBindTexture(GL_TEXTURE_2D, currentID);

	if (glMode == GL_LINE_LOOP)
    {
		renderVerts();

        if (renderMode == GL_SELECT) return;
	}
	
	for(Group* g : groups){	
	
		if(renderMode == GL_SELECT && glMode == GL_POLYGON){
			glLoadName(group_name++);
		}
		
		if(!g->getVisible()){
			continue;
		}
		
		string mtlName = g->getMtl();
		
		if(!mtlName.empty()){
		
			Material* mtl = getMtl(mtlName);
			glMaterialfv(GL_FRONT, GL_SPECULAR, mtl->getSpecular());
			glMaterialfv(GL_FRONT, GL_AMBIENT, mtl->getAmbient());
			glMaterialfv(GL_FRONT, GL_DIFFUSE, mtl->getDiffuse());
			glMaterialf(GL_FRONT, GL_SHININESS, mtl->getShininess());
			
			int tID = mtl->getID();
			if(tID != currentID){
				currentID = tID;
				glBindTexture(GL_TEXTURE_2D, currentID);
			}
		}	
		
		int face_name = 0;

        glColor3f(1.0, 1.0, 1.0);

		for(Face* f : g->getFaces()){
			if (f == face_selected.face)
                glColor3f(0.603922f, 0.803922f, 0.196078f);
			
			vector<int> v = f->getVerts();
			vector<int> n = f->getNorms();
			vector<int> t = f->getTexts();
			
			bool hasNorm = !n.empty();
			bool hasText = !t.empty();
			
			int nv = v.size();
			
			if (renderMode == GL_SELECT && glMode == GL_POLYGON)
				glPushName(face_name++);
		
			glBegin(glMode);
			
			for(int x = 0; x < nv; ++x){
				if(hasNorm) {
					glNormal3fv(norms[n[x]].getCoords());
				}
				if(hasText){
					glTexCoord2fv(texts[t[x]].getCoords());
				}
				glVertex3fv(verts[v[x]].getCoords());
			}
			
			glEnd();
			
			if (renderMode == GL_SELECT && glMode == GL_POLYGON)
				glPopName();

            if (f == face_selected.face)
                glColor3f(1.0, 1.0, 1.0);
		}
	}
	
}
Example #23
0
//
//  Load OBJ file
//
int LoadOBJ(const char* file)
{
   int k;
   int  Nv,Nn,Nt;  //  Number of vertex, normal and textures
   int  Mv,Mn,Mt;  //  Maximum vertex, normal and textures
   float* V;       //  Array of vertexes
   float* N;       //  Array of normals
   float* T;       //  Array if textures coordinates
   char*  line;    //  Line pointer
   char*  str;     //  String pointer

   //  Open file
   FILE* f = fopen(file,"r");
   if (!f) Fatal("Cannot open file %s\n",file);

   // Reset materials
   mtl = NULL;
   Nmtl = 0;

   //  Start new displaylist
   int list = glGenLists(1);
   glNewList(list,GL_COMPILE);
   //  Push attributes for textures
   glPushAttrib(GL_TEXTURE_BIT);

   //  Read vertexes and facets
   V  = N  = T  = NULL;
   Nv = Nn = Nt = 0;
   Mv = Mn = Mt = 0;
   while ((line = readline(f)))
   {
      //  Vertex coordinates (always 3)
      if (line[0]=='v' && line[1]==' ')
         readcoord(line+2,3,&V,&Nv,&Mv);
      //  Normal coordinates (always 3)
      else if (line[0]=='v' && line[1] == 'n')
         readcoord(line+2,3,&N,&Nn,&Mn);
      //  Texture coordinates (always 2)
      else if (line[0]=='v' && line[1] == 't')
         readcoord(line+2,2,&T,&Nt,&Mt);
      //  Read and draw facets
      else if (line[0]=='f')
      {
         line++;
         //  Read Vertex/Texture/Normal triplets
         glBegin(GL_POLYGON);
         while ((str = getword(&line)))
         {
            int Kv,Kt,Kn;
            //  Try Vertex/Texture/Normal triplet
            if (sscanf(str,"%d/%d/%d",&Kv,&Kt,&Kn)==3)
            {
               if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3);
               if (Kn<0 || Kn>Nn/3) Fatal("Normal %d out of range 1-%d\n",Kn,Nn/3);
               if (Kt<0 || Kt>Nt/2) Fatal("Texture %d out of range 1-%d\n",Kt,Nt/2);
            }
            //  Try Vertex//Normal pairs
            else if (sscanf(str,"%d//%d",&Kv,&Kn)==2)
            {
               if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3);
               if (Kn<0 || Kn>Nn/3) Fatal("Normal %d out of range 1-%d\n",Kn,Nn/3);
               Kt = 0;
            }
            //  Try Vertex index
            else if (sscanf(str,"%d",&Kv)==1)
            {
               if (Kv<0 || Kv>Nv/3) Fatal("Vertex %d out of range 1-%d\n",Kv,Nv/3);
               Kn = 0;
               Kt = 0;
            }
            //  This is an error
            else
               Fatal("Invalid facet %s\n",str);
            //  Draw vectors
            if (Kt) glTexCoord2fv(T+2*(Kt-1));
            if (Kn) glNormal3fv(N+3*(Kn-1));
            if (Kv) glVertex3fv(V+3*(Kv-1));
         }
         glEnd();
      }
      //  Use material
      else if ((str = readstr(line,"usemtl")))
         SetMaterial(str);
      //  Load materials
      else if ((str = readstr(line,"mtllib")))
         LoadMaterial(str);
      //  Skip this line
   }
   fclose(f);
   //  Pop attributes (textures)
   glPopAttrib();
   glEndList();

   //  Free materials
   for (k=0;k<Nmtl;k++)
      free(mtl[k].name);
   free(mtl);

   //  Free arrays
   free(V);
   free(T);
   free(N);

   return list;
}
Example #24
0
/*!
   \brief Display fridge

   \todo add elevation for bottom
   add color option
   add ruler grid lines

   \param surf surface (geosurf)
   \param clr
   \param elev
   \param where
 */
void gsd_display_fringe(geosurf * surf, unsigned long clr, float elev,
			int where[4])
{
    float bot, xres, yres;	/* world size of view cell */
    int ycnt, xcnt;		/* number of view cells across */
    float xmax, ymax;

    xres = surf->x_mod * surf->xres;
    yres = surf->y_mod * surf->yres;

    xcnt = VCOLS(surf);
    ycnt = VROWS(surf);

    xmax = surf->xmax;
    ymax = surf->ymax;

    /* 
       bot = surf->zmin - ((surf->zrange/4.) * surf->z_exag);
     */
    bot = elev - ((surf->zrange / 4.) * surf->z_exag);


    gsd_linewidth(FRINGE_WIDTH);
    gsd_colormode(CM_COLOR);

    /* North fringe */
    if (where[0] || where[1]) {
	glNormal3fv(Nnorth);
	gsd_color_func(clr);
	gsd_zwritemask(0x0);
	gsd_fringe_horiz_poly(bot, surf, 0, 0);
	gsd_color_func(FRINGE_FORE);	/* WHITE */
	gsd_fringe_horiz_line(bot, surf, 0, 0);
	gsd_zwritemask(0xffffffff);
	/*   wmpack (0); ??? glColorMask */
	gsd_color_func(clr);
	gsd_fringe_horiz_poly(bot, surf, 0, 0);
    }

    /* South fringe */
    if (where[2] || where[3]) {
	glNormal3fv(Nsouth);
	gsd_color_func(clr);
	gsd_zwritemask(0x0);
	gsd_fringe_horiz_poly(bot, surf, ycnt - 2, 1);
	gsd_color_func(FRINGE_FORE);	/* WHITE */
	gsd_fringe_horiz_line(bot, surf, ycnt - 2, 1);
	gsd_zwritemask(0xffffffff);
	/*   wmpack (0); ??? glColorMask */
	gsd_color_func(clr);
	gsd_fringe_horiz_poly(bot, surf, ycnt - 2, 1);
    }

    /* West fringe */
    if (where[0] || where[2]) {
	glNormal3fv(Nwest);
	gsd_color_func(clr);
	gsd_zwritemask(0x0);
	gsd_fringe_vert_poly(bot, surf, 0, 0);
	gsd_color_func(FRINGE_FORE);
	gsd_fringe_vert_line(bot, surf, 0, 0);
	gsd_zwritemask(0xffffffff);
	gsd_color_func(clr);
	gsd_fringe_vert_poly(bot, surf, 0, 0);
    }

    /* East fringe */
    if (where[1] || where[3]) {
	glNormal3fv(Neast);
	gsd_color_func(clr);
	gsd_zwritemask(0x0);
	gsd_fringe_vert_poly(bot, surf, xcnt - 2, 1);
	gsd_color_func(FRINGE_FORE);
	gsd_fringe_vert_line(bot, surf, xcnt - 2, 1);
	gsd_zwritemask(0xffffffff);
	gsd_color_func(clr);
	gsd_fringe_vert_poly(bot, surf, xcnt - 2, 1);
    }

    return;
}
Example #25
0
static void
Fish008(GLenum cap)
{
	glBegin(cap);
	glNormal3fv(N063);
	glVertex3fv(P063);
	glNormal3fv(N019);
	glVertex3fv(P019);
	glNormal3fv(N029);
	glVertex3fv(P029);
	glEnd();
	glBegin(cap);
	glNormal3fv(N019);
	glVertex3fv(P019);
	glNormal3fv(N063);
	glVertex3fv(P063);
	glNormal3fv(N029);
	glVertex3fv(P029);
	glEnd();
	glBegin(cap);
	glNormal3fv(N063);
	glVertex3fv(P063);
	glNormal3fv(N029);
	glVertex3fv(P029);
	glNormal3fv(N065);
	glVertex3fv(P065);
	glEnd();
	glBegin(cap);
	glNormal3fv(N063);
	glVertex3fv(P063);
	glNormal3fv(N065);
	glVertex3fv(P065);
	glNormal3fv(N029);
	glVertex3fv(P029);
	glEnd();
}
Example #26
0
static void
torus(float r, float R, GLint nsides, GLint rings)
{
    int i, j;
    float theta, phi, theta1, phi1;
    float p0[03], p1[3], p2[3], p3[3];
    float n0[3], n1[3], n2[3], n3[3];

    for (i = 0; i < rings; i++) {
	theta = (float) i *2.0 * M_PI / rings;
	theta1 = (float) (i + 1) * 2.0 * M_PI / rings;
	for (j = 0; j < nsides; j++) {
	    phi = (float) j *2.0 * M_PI / nsides;
	    phi1 = (float) (j + 1) * 2.0 * M_PI / nsides;

	    p0[0] = cos(theta) * (R + r * cos(phi));
	    p0[1] = -sin(theta) * (R + r * cos(phi));
	    p0[2] = r * sin(phi);

	    p1[0] = cos(theta1) * (R + r * cos(phi));
	    p1[1] = -sin(theta1) * (R + r * cos(phi));
	    p1[2] = r * sin(phi);

	    p2[0] = cos(theta1) * (R + r * cos(phi1));
	    p2[1] = -sin(theta1) * (R + r * cos(phi1));
	    p2[2] = r * sin(phi1);

	    p3[0] = cos(theta) * (R + r * cos(phi1));
	    p3[1] = -sin(theta) * (R + r * cos(phi1));
	    p3[2] = r * sin(phi1);

	    n0[0] = cos(theta) * (cos(phi));
	    n0[1] = -sin(theta) * (cos(phi));
	    n0[2] = sin(phi);

	    n1[0] = cos(theta1) * (cos(phi));
	    n1[1] = -sin(theta1) * (cos(phi));
	    n1[2] = sin(phi);

	    n2[0] = cos(theta1) * (cos(phi1));
	    n2[1] = -sin(theta1) * (cos(phi1));
	    n2[2] = sin(phi1);

	    n3[0] = cos(theta) * (cos(phi1));
	    n3[1] = -sin(theta) * (cos(phi1));
	    n3[2] = sin(phi1);

	    glBegin(GL_QUADS);
	    glNormal3fv(n3);
	    glTexCoord2f(((float)i)/rings, (j+1.f)/nsides);
	    glVertex3fv(p3);
	    glNormal3fv(n2);
	    glTexCoord2f((i+1.f)/rings, (j+1.f)/nsides);
	    glVertex3fv(p2);
	    glNormal3fv(n1);
	    glTexCoord2f((i+1.f)/rings, ((float)j)/nsides);
	    glVertex3fv(p1);
	    glNormal3fv(n0);
	    glTexCoord2f(((float)i)/rings, ((float)j)/nsides);
	    glVertex3fv(p0);
	    glEnd();
	}
    }
}
Example #27
0
static void
Fish002(GLenum cap)
{
	glBegin(cap);
	glNormal3fv(N013);
	glVertex3fv(P013);
	glNormal3fv(N014);
	glVertex3fv(P014);
	glNormal3fv(N024);
	glVertex3fv(P024);
	glNormal3fv(N023);
	glVertex3fv(P023);
	glEnd();
	glBegin(cap);
	glNormal3fv(N014);
	glVertex3fv(P014);
	glNormal3fv(N015);
	glVertex3fv(P015);
	glNormal3fv(N025);
	glVertex3fv(P025);
	glNormal3fv(N024);
	glVertex3fv(P024);
	glEnd();
	glBegin(cap);
	glNormal3fv(N016);
	glVertex3fv(P016);
	glNormal3fv(N017);
	glVertex3fv(P017);
	glNormal3fv(N027);
	glVertex3fv(P027);
	glNormal3fv(N026);
	glVertex3fv(P026);
	glEnd();
	glBegin(cap);
	glNormal3fv(N017);
	glVertex3fv(P017);
	glNormal3fv(N018);
	glVertex3fv(P018);
	glNormal3fv(N028);
	glVertex3fv(P028);
	glNormal3fv(N027);
	glVertex3fv(P027);
	glEnd();
	glBegin(cap);
	glNormal3fv(N020);
	glVertex3fv(P020);
	glNormal3fv(N021);
	glVertex3fv(P021);
	glNormal3fv(N031);
	glVertex3fv(P031);
	glNormal3fv(N030);
	glVertex3fv(P030);
	glEnd();
	glBegin(cap);
	glNormal3fv(N013);
	glVertex3fv(P013);
	glNormal3fv(N023);
	glVertex3fv(P023);
	glNormal3fv(N022);
	glVertex3fv(P022);
	glEnd();
	glBegin(cap);
	glNormal3fv(N022);
	glVertex3fv(P022);
	glNormal3fv(N023);
	glVertex3fv(P023);
	glNormal3fv(N032);
	glVertex3fv(P032);
	glEnd();
	glBegin(cap);
	glNormal3fv(N022);
	glVertex3fv(P022);
	glNormal3fv(N032);
	glVertex3fv(P032);
	glNormal3fv(N031);
	glVertex3fv(P031);
	glEnd();
	glBegin(cap);
	glNormal3fv(N022);
	glVertex3fv(P022);
	glNormal3fv(N031);
	glVertex3fv(P031);
	glNormal3fv(N021);
	glVertex3fv(P021);
	glEnd();
	glBegin(cap);
	glNormal3fv(N018);
	glVertex3fv(P018);
	glNormal3fv(N019);
	glVertex3fv(P019);
	glNormal3fv(N029);
	glVertex3fv(P029);
	glEnd();
	glBegin(cap);
	glNormal3fv(N018);
	glVertex3fv(P018);
	glNormal3fv(N029);
	glVertex3fv(P029);
	glNormal3fv(N028);
	glVertex3fv(P028);
	glEnd();
	glBegin(cap);
	glNormal3fv(N019);
	glVertex3fv(P019);
	glNormal3fv(N020);
	glVertex3fv(P020);
	glNormal3fv(N030);
	glVertex3fv(P030);
	glEnd();
	glBegin(cap);
	glNormal3fv(N019);
	glVertex3fv(P019);
	glNormal3fv(N030);
	glVertex3fv(P030);
	glNormal3fv(N029);
	glVertex3fv(P029);
	glEnd();
}
Example #28
0
static void Display( void )
{
   const struct interleave_info * const curr_info = info[ interleave_mode ];

   /* 4 floats for 12 verticies for 4 data elements.
    */
   char data[ (sizeof( GLfloat ) * 4) * 12 * 4 ];

   unsigned i;
   unsigned offset;
   GLenum err;
   GLenum format;
   GLsizei stride;


   glClearColor(0.2, 0.2, 0.8, 0);
   glClear( GL_COLOR_BUFFER_BIT );

   glPushMatrix();

   glTranslatef(-1.5, 0, 0);

   glColor3fv( c_f[0] );

   if ( curr_info[0].data != NULL ) {
      glEnable( GL_TEXTURE_2D );
   }
   else {
      glDisable( GL_TEXTURE_2D );
   }


   offset = 0;
   glBegin(GL_TRIANGLES);
   for ( i = 0 ; i < 12 ; i++ ) {
      const unsigned index = indicies[i];


      /* Handle the vertex texture coordinate.
       */
      if ( curr_info[0].data != NULL ) {
	 if ( curr_info[0].count == 2 ) {
	    glTexCoord2fv( DEREF(0, index) );
	 }
	 else {
	    glTexCoord4fv( DEREF(0, index) );
	 }

	 (void) memcpy( & data[ offset ], DEREF(0, index),
			curr_info[0].size );
	 offset += curr_info[0].size;
      }


      /* Handle the vertex color.
       */
      if ( curr_info[1].data != NULL ) {
	 if ( curr_info[1].type == GL_FLOAT ) {
	    if ( curr_info[1].count == 3 ) {
	       glColor3fv( DEREF(1, index) );
	    }
	    else {
	       glColor4fv( DEREF(1, index) );
	    }
	 }
	 else {
	    glColor4ubv( DEREF(1, index) );
	 }

	 (void) memcpy( & data[ offset ], DEREF(1, index), 
			curr_info[1].size );
	 offset += curr_info[1].size;
      }

      
      /* Handle the vertex normal.
       */
      if ( curr_info[2].data != NULL ) {
	 glNormal3fv( DEREF(2, index) );

	 (void) memcpy( & data[ offset ], DEREF(2, index),
			curr_info[2].size );
	 offset += curr_info[2].size;
      }


      switch( curr_info[3].count ) {
      case 2:
	 glVertex2fv( DEREF(3, index) );
	 break;
      case 3:
	 glVertex3fv( DEREF(3, index) );
	 break;
      case 4:
	 glVertex4fv( DEREF(3, index) );
	 break;
      }

      (void) memcpy( & data[ offset ], DEREF(3, index),
		     curr_info[3].size );
	 offset += curr_info[3].size;
   }
   glEnd();


   glTranslatef(3.0, 0, 0);

   /* The masking with ~0x2A00 is a bit of a hack to make sure that format
    * ends up with an invalid value no matter what rand() returns.
    */
   format = (use_invalid_mode)
     ? (rand() & ~0x2A00) : GL_V2F + interleave_mode;
   stride = (use_invalid_stride) ? -abs(rand()) : 0;

   (void) glGetError();
   glInterleavedArrays( format, stride, data );
   err = glGetError();
   if ( err ) {
      printf("glInterleavedArrays(0x%04x, %d, %p) generated the error 0x%04x\n",
	     format, stride, data, err );
   }
   else {
      glDrawArrays( GL_TRIANGLES, 0, 12 );
   }

   glPopMatrix();

   glutSwapBuffers();
}
Example #29
0
static void
Fish004(GLenum cap)
{
	glBegin(cap);
	glNormal3fv(N040);
	glVertex3fv(P040);
	glNormal3fv(N041);
	glVertex3fv(P041);
	glNormal3fv(N051);
	glVertex3fv(P051);
	glNormal3fv(N050);
	glVertex3fv(P050);
	glEnd();
	glBegin(cap);
	glNormal3fv(N041);
	glVertex3fv(P041);
	glNormal3fv(N042);
	glVertex3fv(P042);
	glNormal3fv(N052);
	glVertex3fv(P052);
	glNormal3fv(N051);
	glVertex3fv(P051);
	glEnd();
	glBegin(cap);
	glNormal3fv(N042);
	glVertex3fv(P042);
	glNormal3fv(N033);
	glVertex3fv(P033);
	glNormal3fv(N043);
	glVertex3fv(P043);
	glNormal3fv(N052);
	glVertex3fv(P052);
	glEnd();
	glBegin(cap);
	glNormal3fv(N033);
	glVertex3fv(P033);
	glNormal3fv(N034);
	glVertex3fv(P034);
	glNormal3fv(N044);
	glVertex3fv(P044);
	glNormal3fv(N043);
	glVertex3fv(P043);
	glEnd();
	glBegin(cap);
	glNormal3fv(N034);
	glVertex3fv(P034);
	glNormal3fv(N035);
	glVertex3fv(P035);
	glNormal3fv(N045);
	glVertex3fv(P045);
	glNormal3fv(N044);
	glVertex3fv(P044);
	glEnd();
	glBegin(cap);
	glNormal3fv(N035);
	glVertex3fv(P035);
	glNormal3fv(N036);
	glVertex3fv(P036);
	glNormal3fv(N046);
	glVertex3fv(P046);
	glNormal3fv(N045);
	glVertex3fv(P045);
	glEnd();
	glBegin(cap);
	glNormal3fv(N036);
	glVertex3fv(P036);
	glNormal3fv(N037);
	glVertex3fv(P037);
	glNormal3fv(N047);
	glVertex3fv(P047);
	glNormal3fv(N046);
	glVertex3fv(P046);
	glEnd();
	glBegin(cap);
	glNormal3fv(N037);
	glVertex3fv(P037);
	glNormal3fv(N038);
	glVertex3fv(P038);
	glNormal3fv(N048);
	glVertex3fv(P048);
	glNormal3fv(N047);
	glVertex3fv(P047);
	glEnd();
	glBegin(cap);
	glNormal3fv(N038);
	glVertex3fv(P038);
	glNormal3fv(N039);
	glVertex3fv(P039);
	glNormal3fv(N049);
	glVertex3fv(P049);
	glNormal3fv(N048);
	glVertex3fv(P048);
	glEnd();
	glBegin(cap);
	glNormal3fv(N039);
	glVertex3fv(P039);
	glNormal3fv(N040);
	glVertex3fv(P040);
	glNormal3fv(N050);
	glVertex3fv(P050);
	glNormal3fv(N049);
	glVertex3fv(P049);
	glEnd();
	glBegin(cap);
	glNormal3fv(N070);
	glVertex3fv(P070);
	glNormal3fv(N061);
	glVertex3fv(P061);
	glNormal3fv(N002);
	glVertex3fv(P002);
	glEnd();
	glBegin(cap);
	glNormal3fv(N061);
	glVertex3fv(P061);
	glNormal3fv(N046);
	glVertex3fv(P046);
	glNormal3fv(N002);
	glVertex3fv(P002);
	glEnd();
	glBegin(cap);
	glNormal3fv(N045);
	glVertex3fv(P045);
	glNormal3fv(N046);
	glVertex3fv(P046);
	glNormal3fv(N061);
	glVertex3fv(P061);
	glEnd();
	glBegin(cap);
	glNormal3fv(N002);
	glVertex3fv(P002);
	glNormal3fv(N061);
	glVertex3fv(P061);
	glNormal3fv(N070);
	glVertex3fv(P070);
	glEnd();
	glBegin(cap);
	glNormal3fv(N002);
	glVertex3fv(P002);
	glNormal3fv(N045);
	glVertex3fv(P045);
	glNormal3fv(N061);
	glVertex3fv(P061);
	glEnd();
}
Example #30
0
static void draw(void) {
	int i,j,k;
	float size = CUBE_SIZE;
	float normals[6][3] = {
		{ 0.0,  0.0, -1.0},
		{ 1.0,  0.0,  0.0},
		{ 0.0,  0.0,  1.0},
		{-1.0,  0.0,  0.0},
		{ 0.0,  1.0,  0.0},
		{ 0.0, -1.0,  0.0}
	};
		
	float cube_points[8][3] ={
		{ -size, -size, -size },
		{  size, -size, -size },
		{  size, -size,  size },
		{ -size, -size,  size },
		{ -size,  size, -size },
		{  size,  size, -size },
		{  size,  size,  size },
		{ -size,  size,  size }
	};

	/* 3Dオブジェクトを描画するための準備 */
	argDrawMode3D();
	argDraw3dCamera(0, 0);


	glClear(GL_DEPTH_BUFFER_BIT); //バッファの消去
	glEnable( GL_DEPTH_TEST );		// 陰面処理の適用

	mySetLight();
	glEnable( GL_LIGHTING );

	myMatrix(object[PTT1_MARK_ID].patt_trans);
	
	renew(); // フレーム毎の更新内容

	// 立方体
	glPushMatrix();
		glTranslated( c_trans[0], c_trans[1], c_trans[2]);//平行移動値の設定
		glRotatef(c_angle[0], 1.0, 0.0, 0.0 );
		glRotatef(c_angle[1], 0.0, 1.0, 0.0 );
		glRotatef(c_angle[2], 0.0, 0.0, 1.0 );
		
		/* 前 */
		glEnable( GL_TEXTURE_2D );
		glBegin( GL_QUADS );
			mySetMaterial( 1.0, 1.0, 1.0 );
			glBindTexture(GL_TEXTURE_2D, texture);
			glNormal3fv(normals[0]);
			glTexCoord2f(0.0, 1.0); glVertex3fv(cube_points[0]);
			glTexCoord2f(1.0, 1.0); glVertex3fv(cube_points[1]);
			glTexCoord2f(1.0, 0.0); glVertex3fv(cube_points[5]);
			glTexCoord2f(0.0, 0.0); glVertex3fv(cube_points[4]);
		glEnd();
		glDisable( GL_TEXTURE_2D );
		
		/* 右 */
		glBegin( GL_QUADS );
			mySetMaterial( 0.0, 1.0, 0.0);
			glNormal3fv(normals[1]);
			glVertex3fv(cube_points[1]);
			glVertex3fv(cube_points[2]);
			glVertex3fv(cube_points[6]);
			glVertex3fv(cube_points[5]);
		glEnd();

		/* 後ろ */
		glBegin( GL_QUADS );
			mySetMaterial( 0.0, 1.0, 1.0);
			glNormal3fv(normals[2]);
			glVertex3fv(cube_points[2]);
			glVertex3fv(cube_points[3]);
			glVertex3fv(cube_points[7]);
			glVertex3fv(cube_points[6]);
		glEnd();

		/* 左 */
		glBegin( GL_QUADS );
			mySetMaterial( 1.0, 0.0, 1.0);
			glNormal3fv(normals[3]);
			glVertex3fv(cube_points[3]);
			glVertex3fv(cube_points[0]);
			glVertex3fv(cube_points[4]);
			glVertex3fv(cube_points[7]);
		glEnd();

		/* 上 */
		glBegin( GL_QUADS );
			mySetMaterial( 0.0, 0.0, 1.0);
			glNormal3fv(normals[4]);
			glVertex3fv(cube_points[4]);
			glVertex3fv(cube_points[5]);
			glVertex3fv(cube_points[6]);
			glVertex3fv(cube_points[7]);
		glEnd();

		/* 下 */
		glBegin( GL_QUADS );
			mySetMaterial( 1.0, 1.0, 0.0);
			glNormal3fv(normals[5]);
			glVertex3fv(cube_points[0]);
			glVertex3fv(cube_points[1]);
			glVertex3fv(cube_points[2]);
			glVertex3fv(cube_points[3]);
		glEnd();

	glPopMatrix();


	glDisable( GL_LIGHTING );
	glDisable( GL_DEPTH_TEST );		// 陰面処理の適用
}