示例#1
0
文件: Sky.cpp 项目: DCubix/1.4.0
CInt CSkyDome::Initialize()
{
	m_numIndices = m_numSlices * (m_numSides + 1) * 2;
	
	m_vertexBuffer = CNewData( CVec3f, (m_numSlices + 1) * (m_numSides + 1) );
	//m_colorBuffer = CNewData( CColor4f, (Slices + 1) * (Sides + 1) );
	m_texCoordBuffer = CNewData( CVec2f, (m_numSlices + 1) * (m_numSides + 1) );
	//m_skyMapTexCoordBuffer = CNewData( CVec2f, (Slices + 1) * (Sides + 1) );

	m_indexBuffer = CNewData( unsigned short, m_numIndices );
	
	CFloat polyAng = 2.0f * PI / m_numSides, ang;

	m_exponential = CFalse; //use to tesselate
		
	CFloat vx, vy, vz;
	
	CInt i, j;
	for (j = 0; j <= m_numSlices; j++)
	{
		ang = j * ( (PI / 2) / m_numSlices );
		for (i = 0; i <= m_numSides; i++)
		{						
			vx = cos(i * polyAng) * cos(ang);
			vy = sin(ang) * m_dampening;
			vz = sin(i * polyAng) * cos(ang);

			m_vertexBuffer[j * (m_numSides + 1) + i].x = vx * m_radius;
			m_vertexBuffer[j * (m_numSides + 1) + i].z = vz * m_radius;
			m_vertexBuffer[j * (m_numSides + 1) + i].y = vy * m_radius;	

			m_texCoordBuffer[j * (m_numSides + 1) + i].x = (CFloat)(i) / (CFloat)(m_numSides);
			m_texCoordBuffer[j * (m_numSides + 1) + i].y = (CFloat)(j) / (CFloat)(m_numSlices);

            //m_skyMapTexCoordBuffer[j * (Sides + 1) + i].y = (CFloat)(j) / (CFloat)(Slices);
		}
	}
	
	CInt ind = 0;
	for (j = 1; j <= m_numSlices; j++)
	{
		for (i = 0; i <= m_numSides; i++)
		{			
			m_indexBuffer[ind++] =  j * (m_numSides + 1) + i;
			m_indexBuffer[ind++] = (j - 1) * (m_numSides + 1) + i;
		}
	}
	SetSkyTexture( m_path );
	SetIndex();
	return 1;
}
示例#2
0
文件: Water.cpp 项目: DCubix/1.4.0
void CWater::CreateRenderTexture( CInt size, CInt channels, CInt type, CInt textureID)										
{
	glGenTextures(1, &m_waterTexture[textureID]);								
	glBindTexture(GL_TEXTURE_2D, m_waterTexture[textureID]);					
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	if ( g_render.UsingFBOs() && g_options.m_enableFBO )
	{
		glGenerateMipmapEXT( GL_TEXTURE_2D );
		glTexImage2D(GL_TEXTURE_2D, 0, channels, size, size, 0, type, GL_UNSIGNED_BYTE, NULL );
		m_fboID[textureID] = g_render.GenerateFBO();
		g_render.BindFBO( m_fboID[textureID] );
		g_render.Attach2DTextureToFBOColor( m_waterTexture[textureID] );
		m_rbID[textureID] = g_render.GenerateRenderBuffer();
		g_render.BindRenderBuffer( m_rbID[textureID] );
		g_render.RenderbufferStorage( size, size );
		g_render.AttachDepthToFBO( m_rbID[textureID] );
		g_render.BindFBO(0);
		g_render.BindRenderBuffer(0);

		GLenum status;
		status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
		switch(status)
		{
			case GL_FRAMEBUFFER_COMPLETE_EXT:
				break;
			default:
				MessageBox( NULL, _T("An error occured while creating the FBO for water\n"), _T( "VandaEngine Error" ), MB_OK );
				break;
		}
	}
	else
	{
		glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
		glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST );
		CUInt *pTexture = NULL;											
		pTexture = CNewData( CUInt, size * size * channels );
		memset(pTexture, 0, size * size * channels * sizeof(CUInt));	
		glTexImage2D(GL_TEXTURE_2D, 0, channels, size, size, 0, type, GL_UNSIGNED_BYTE, pTexture);
		CDeleteData( pTexture );																					
	}
	glBindTexture(GL_TEXTURE_2D, 0);

}
示例#3
0
//CBool CTexture::LoadTargaTexture( CImage * texObj, CChar* name, CChar* sceneFileName ) 
//{
//	//attache the sceneFileName path( without the dea file ) to the texture name
//	CChar pathName[MAX_NAME_SIZE]; 
//
//	if( sceneFileName ) //To deal with COLLADA files.
//	{
//		CChar * texName = GetAfterPath( name ); //don't know if it's required? Maybe the name in collada file has no path
//		//strcpy( pathName , sceneFileName );
//		//CChar *removeExtra = GetAfterPath( pathName );
//		//removeExtra[0] = 0;
//		//strcat( pathName, texName );
//		//save functions. it should be copies in WIN32 Project as well
//		CChar g_currentVSceneNameWithoutDot[MAX_NAME_SIZE];
//		Cpy( g_currentVSceneNameWithoutDot, g_currentVSceneName );
//		GetWithoutDot( g_currentVSceneNameWithoutDot );
//
//		sprintf( pathName, "%s%s%s%s", "assets/vscenes/", g_currentVSceneNameWithoutDot, "/Textures/", texName );
//
//	}
//	else //To load independent targa files(not specified in a collada file )
//		strcpy( pathName, name );
//
//	ILuint imageId;
//	ilGenImages(1, &imageId);
//	ilBindImage(imageId);
//
//	PrintInfo( _T( "\nReading Image : " ) );
//	PrintInfo( _T( "'" ) + CString( pathName ) + _T("'"), COLOR_RED_GREEN );
//
//	// Read in the image file into DevIL.
//	if (!ilLoadImage(pathName)) {
//		// ERROR
//		ilDeleteImages(1, &imageId);
//		CChar temp[MAX_NAME_SIZE];
//		sprintf( temp, "\nError! CTexture::LoadTargaTexture > Couldn't load the targa file: '%s'", pathName );
//	    PrintInfo( temp, COLOR_RED );
//		numErrors += 1;
//
//		return false;
//	}
//	else {
//		texObj->SetWidth( ilGetInteger(IL_IMAGE_WIDTH) );
//		texObj->SetHeight( ilGetInteger(IL_IMAGE_HEIGHT) );
//
//		CUChar* imageData;
//		CInt imageSize;
//
//		imageSize = ilGetInteger(IL_IMAGE_WIDTH) * ilGetInteger(IL_IMAGE_HEIGHT) * ilGetInteger(IL_IMAGE_CHANNELS);
//		imageData = (CUChar*)malloc( imageSize );
//
//		if( ilGetInteger(IL_IMAGE_CHANNELS) == 3 )
//			texObj->SetFormat( TGA_TRUECOLOR_24 );
//		else if ( ilGetInteger(IL_IMAGE_CHANNELS) == 4 )
//			texObj->SetFormat( TGA_TRUECOLOR_32 );
//
//		memcpy( imageData , ilGetData() , imageSize );
//		texObj->SetImageData( imageData );
//		ilDeleteImages(1, &imageId);
//	}
//	PrintInfo( "\nCreating Texture '" );
//	PrintInfo(pathName, COLOR_RED_GREEN); 
//	PrintInfo( "' ");
//
//	CreateTargaTexture( texObj );
//
//	return CTrue;
//}
//
CBool CTexture::LoadDDSTexture( CImage * texObj, CChar* name, CChar* sceneFileName, CBool reportError ) 
{
	//attache the sceneFileName path( without the dea file ) to the texture name
	CChar pathName[MAX_NAME_SIZE]; 

	if( sceneFileName ) //To deal with COLLADA files.
	{
		CChar * texName = NULL;
		if( g_useOriginalPathOfDAETextures || g_updateTextureViaEditor)
		{
			texName = CNewData(CChar,MAX_NAME_SIZE);
			Cpy( texName, name );
		}
		else
		{
			texName = GetAfterPath( name ); 
		}
		GetWithoutDot( texName);
		Append( texName, ".dds" );

		//replace %20 with space using std::string
		std::string s(texName);
		size_t i = 0;
		for (;;) {
			i = s.find("%20", i);
			if (i == string::npos) {
				break;
			}
			s.replace(i, 3, " ");
		}
		if( g_useOriginalPathOfDAETextures || g_updateTextureViaEditor)
		{
			s.begin();
			size_t i = 0;
			for (;;) {
				i = s.find("file:/", i);
				if (i == string::npos) {
					break;
				}
				s.replace(i, 6, "");
			}

		}
		strcpy(texName, s.c_str());
		if( g_useOriginalPathOfDAETextures || g_updateTextureViaEditor)
		{
			strcpy( pathName, texName );
			CDelete(texName);
		}
		else
		{
			CChar g_currentVSceneNameWithoutDot[MAX_NAME_SIZE];
			Cpy( g_currentVSceneNameWithoutDot, g_currentVSceneName );
			GetWithoutDot( g_currentVSceneNameWithoutDot );
			sprintf( pathName, "%s%s%s%s", g_VScenePath, g_currentVSceneNameWithoutDot, "/Textures/", texName );

		}
	}
	else //To load independent dds files(not specified in a collada file )
		strcpy( pathName, name );

	ifstream file(pathName, ios::binary);

	if (! file )
	{
		if( reportError )
		{
			CChar temp[MAX_NAME_SIZE];
			sprintf( temp, "\nError! CTexture::LoadDDSTexture > Couldn't load the dds file: '%s'", pathName );
			PrintInfo( temp, COLOR_RED );
			numErrors += 1;
		}

		return false;
	}

	CDDS *m_ddsImage = CNew( CDDS );

	if (! m_ddsImage->LoadFile(file) )
	{
		if( reportError )
		{
			CChar temp[MAX_NAME_SIZE];
			sprintf( temp, "\nError! CTexture::LoadDDSTexture > Couldn't load the dds file: '%s'", pathName );
			PrintInfo( temp, COLOR_RED );
			numErrors += 1;
		}

		return false;
	}
	texObj->SetWidth( (CInt32)m_ddsImage->GetWidth() );
	texObj->SetHeight( (CInt32)m_ddsImage->GetHeight() );
	if( m_ddsImage->m_alphaChannel)
		texObj->SetFormat(TGA_TRUECOLOR_32);
	else
		texObj->SetFormat(TGA_TRUECOLOR_24);

	PrintInfo( "\nCreating Texture ' " );
	PrintInfo(pathName, COLOR_RED_GREEN); 
	PrintInfo( " '");

	CreateDDSTexture( texObj, m_ddsImage );

	return CTrue;
}