Jump to content
  • Advertisement
Sign in to follow this  
treeway

OpenGL DevIL & DDS Cube Maps

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I'm working with DevIL and OpenGL/DirectX. In the OpenGL implementation, I want to load a cube map texture stored in a DDS format 32 bit per pixel with 8 bit ARGB. In the DevIL DirectX library it has
ilutD3D9CubeTexFromFile

for loading cube maps - equivilent to D3DXCreateCubeTextureFromFile. In OpenGL, I'm using
	ilutRenderer(ILUT_OPENGL);
	
//FileName for 2D (standard) texture.
	char* fileName1 = (char*)CgEffect.mappedTextures[0]->fileName;

	int texture = ilutGLLoadImage(fileName1);				
// Send texture to GPU
	cgGLSetupSampler(tmpParam, texture);

// FileName for Cubemap Tuexture.
	char* fileName2 = (char*)CgEffect.mappedTextures[1]->fileName;
	int texture2 = ilutGLLoadImage(fileName2);				
//Send CubeMap to GPU
	cgGLSetupSampler(envParam, texture2);


Im sending the Textures to a CGFX effect which looks fine in NVIDIA FX Composer but when I run my code it appears as if the cube map is completley black (the 2D Texture works fine).
/*

% Default + Textured + Bump Effect.

keywords: material classic

date: 02/09/2008

*/

float4x4 WorldViewProj : WorldViewProjection;
float4x4 matWorld : World;
float4 viewPos : CAMERAPOSITION;
float4 lightPos0 = float4(0.0f,10.0f,0.0f,1.0f);
float4 ambient = float4(0.8f,0.8f,0.8f,1.0f);
float shinyness = 0.9f;
float pTime : TIME;


texture diffuse_texture : DIFFUSE
<
	string ResourceName = "default.dds";
	string UIName = "Diffuse Texture";
	string ResourceType = "2d";
>;

sampler2D diffuse_sampler = sampler_state
{
	Texture = <diffuse_texture>;
	generateMipMap = true;
	MagFilter = Linear;
	MinFilter = Linear;

	AddressU = WRAP;
	AddressV = WRAP;	
};

textureCUBE reflection_texture : ENVIRONMENT
<
	string ResourceName = "environment.dds";
	string UIName = "Reflection Texture";
	string ResourceType = "Cube";
>;

samplerCUBE environment_sampler = sampler_state
{
	Texture = <reflection_texture>;
	
	generateMipMap = true;
	MagFilter = Linear;
	MinFilter = Linear;

		
	AddressU = Clamp;
	AddressV = Clamp;	
};


struct vs_Input
{
	float4 pos  	: POSITION;
	float4 Diffuse	: COLOR0;
	float4 norm		: NORMAL;
	float4 tex0		: TEXCOORD0;
};

struct vs_Output
{
	float4 pos  		: POSITION;
	float4 pos1 		: TEXCOORD0;
	float4 Diffuse		: TEXCOORD1;
	float4 norm			: TEXCOORD2;
	float4 tex0			: TEXCOORD3;
	float3 reflection	: TEXCOORD4;
};


vs_Output mainVS(vs_Input pIn) 
{
	vs_Output pOut;
	
	pOut.pos = mul(WorldViewProj,pIn.pos);
	//pOut.pos.y += sin(pTime);
	pOut.pos1 = pOut.pos;
	pOut.norm = normalize(pIn.norm);
	pOut.tex0 = pIn.tex0;
	pOut.tex0.y += pTime / 1000;
	
	float4 woldSpaceNormal = normalize(mul(matWorld,pOut.norm));
	
	//get a vector toward the camera y
	float4 posWorld = normalize(mul(matWorld,pIn.pos));
	float4 Incident = normalize(posWorld - viewPos);
	
	//Reflection vector for cubemap: R = 1 - 2*N * (I.N)
	pOut.reflection.xyz = reflect(Incident.xyz,woldSpaceNormal.xyz);

	return pOut;
}

float4 mainPS(vs_Output pIn) : COLOR 
{
	float4 L = normalize(lightPos0 - pIn.pos1);
	float NdotL = dot(pIn.norm,L);
	float4 reflection = float4(texCUBE(environment_sampler,pIn.reflection).xyz,1.0f);
	
	return (reflection * shinyness )+ (ambient + float4(max(0.0f,NdotL))) * tex2D(diffuse_sampler,pIn.tex0.xy);
	
}

technique technique0 
{
	pass p0 
	{
		VertexProgram = compile vp40 mainVS();
		
		DepthTestEnable = true;
		DepthMask = true;
		CullFaceEnable = false;
		BlendEnable = true;
		DepthFunc = LEqual;
		
		FragmentProgram = compile fp40 mainPS();
	}
}

Is there any way to load a cube map in DevIL? Any help would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
The last time I tried I couldn't make it work.
I implemented a dds loader myself and the good news is that it is really easy.
http://msdn.microsoft.com/en-us/library/bb943991(VS.85).aspx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!