Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void OgreOculusRender::writeTextureToFile()
- {
- //It's a C style function, yeah...
- char path[] = "debug.ppm";
- FILE* debugFile = fopen(path,"w");
- fprintf(debugFile,"P3\n");//PPM ASCII MAGIC NUMBER
- //W H size
- fprintf(debugFile, "%d %d\n" ,texSizeL.w, texSizeL.h);
- //Compute the biggest nomber an unsigned int cat represent on this computer :
- unsigned int max = 0;
- max--;
- //MAX SUBPIXEL VALULE
- fprintf(debugFile, "%u\n", 255);
- size_t arraySize = texSizeL.w*texSizeL.h;
- //Cast because C++ will not like affecting a void* on a int*
- unsigned int* rIntArray = static_cast<unsigned int*>(malloc(sizeof(unsigned int) * arraySize));
- unsigned int* gIntArray = static_cast<unsigned int*>(malloc(sizeof(unsigned int) * arraySize));
- unsigned int* bIntArray = static_cast<unsigned int*>(malloc(sizeof(unsigned int) * arraySize));
- GLuint tex = static_cast<Ogre::GLTexture*>(Ogre::GLTextureManager::getSingleton().getByName("RttTexL").get())->getGLID();
- glBindTexture(GL_TEXTURE_2D, tex);
- //I'm not searching to do this right, I just want to get the data in any format I can...
- glGetTexImage(GL_TEXTURE_2D,0, GL_RED,GL_UNSIGNED_INT, static_cast<GLvoid*>(rIntArray));
- glGetTexImage(GL_TEXTURE_2D,0, GL_GREEN, GL_UNSIGNED_INT, static_cast<GLvoid*>(gIntArray));
- glGetTexImage(GL_TEXTURE_2D,0, GL_BLUE, GL_UNSIGNED_INT, static_cast<GLvoid*>(bIntArray));
- //Convert to a 255 max value
- for(int i = 0; i < arraySize; i++)
- {
- rIntArray[i] =(int) (((float)rIntArray[i]/(float)max)*(float)255);
- gIntArray[i] =(int) (((float)gIntArray[i]/(float)max)*(float)255);
- bIntArray[i] =(int) (((float)bIntArray[i]/(float)max)*(float)255);
- }
- for(int i = 0; i < arraySize; i++)
- {
- fprintf(debugFile,"%u %u %u ",rIntArray[i], gIntArray[i], bIntArray[i]);
- }
- free(rIntArray);
- free(gIntArray);
- free(bIntArray);
- fclose(debugFile);
- }
Advertisement
Add Comment
Please, Sign In to add comment