Reputation: 21
I am working on an external plugin for Unity that updates the in game textures by reading DDS files. So far I was able to get DDS files to load in DX11 and DX9, but I can't seem to get OpenGL to work.
I am using the nvidia graphics sdk 10 for opengl to read the DDS files and GLUT/GLEW to update the texture, but the texture won't update in game. I am trying to read a 2048x2048 DXT1 texture with 12 mipmaps.
Here is my code:
// Initialize glut/glew
glutCreateWindow("");
char *args[] = {0};
glutInit(0, args);
GLenum err = glewInit();
if (GLEW_OK != err)
{
char message[64];
sprintf_s(message, "Error: %s", glewGetErrorString(err));
DebugLog(message);
}
// Load the DDS file
nv::Image texture;
if (!texture.loadImageFromFile("image.dds"))
DebugLog("Failed to load DDS texture");
// Update the texture
GLuint gltex = (GLuint)(g_TexturePointer); // g_TexturePointer is a pointer to the texture that is passed from Unity
//glGenTextures(1, &gltex);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, gltex);
for (int i = 0; i < texture.getMipLevels(); i++)
{
glCompressedTexImage2DARB(GL_TEXTURE_2D, i, texture.getInternalFormat(), texture.getWidth(), texture.getHeight(), 0, texture.getImageSize(i), texture.getLevel(i));
}
I'm not very experienced with opengl so maybe I'm missing something. If you need more info, please let me know.
Upvotes: 1
Views: 1137