PDA

View Full Version : DirectX to OpenGL translation...



savage
29-03-2008, 04:48 PM
Hi guys,
I searched the netz, but could not find a page which showed how to port DirectX 3D calls to OpenGL. Does anyone here know what the following calls become in OpenGL...



GR_D3D_Device.SetTextureStageState(0,D3DTSS_ADDRES SU,D3DTADDRESS_CLAMP);
GR_D3D_Device.SetTextureStageState(0,D3DTSS_ADDRES SV,D3DTADDRESS_CLAMP);
GR_D3D_Device.SetTexture(0,tex);
GR_D3D_Device.SetVertexShader(SHADER_TEX);
GR_D3D_Device.DrawPrimitiveUp(D3DPT_TRIANGLEFAN, 2, vvv, SizeOf(VERTEX_TEX));


Thanks.

grudzio
29-03-2008, 08:52 PM
This is how I would translate the D3D code to OpenGL (2.0)

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _CLAMP);
glUseProgram(SHADER_TEX);
glDrawArrays(GL_TRIANGLE_FAN,0,2);


The code above assumes that tex is the texture identifier,
SHADER_TEX is theshader id.

The call to glActiveTexture sets the texture stage - it corresponds to first parameter in SetTexture and setTextureStageState.

glDrawArrays function is the closest equivalent of DrawPrimitiveUP I can think of.

This is a literal translation, I assumed that you have created the texture, the shader prgram and prepared the geometry data to be rendered with glDrawArrays.