cancel
Showing results for 
Search instead for 
Did you mean: 

Loading Image as a Texture

Anonymous
Not applicable
Hello!
I have been trying to load an image and the raw data as a texture to the VrCubeWorld_SurfaceView example in Mobile SDK, but It seems like I am missing something because application crashes when I run it. This is what I have done so far:

Custom function for loading image (raw data, 512*515 8bit image)
GLint loadTexture(char* imagePath) {
GLint newTexture;
FILE * file;
char *data = (char *)malloc( 512*512 * sizeof( char ) );

file = fopen(imagePath, "rb");
fread(data, 1, 512*512, file);

GL( glGenTextures(1, &newTexture));
GL( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT));
GL( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT));
GL( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GL( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GL( glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, 512, 512, 0, GL_RED, GL_UNSIGNED_BYTE, data));
GL( glGenerateMipmap(GL_TEXTURE_2D));
GL( glBindTexture(GL_TEXTURE_2D, 0));

fclose(file);
return newTexture;
}
Global Variable
GLint texture1 = loadTexture("/../../assets/lena.raw");
Inside ovrProgram_Create
...
texture1 = glGetUniformLocation( program->Program, "passTexture" );
...
Vertex Shader
...
"out vec2 TexPosition;\n"
... 
"  TexPosition = vec2(vertexPosition.x, vertexPosition.y);\n"
...
Fragment Shader
...
"in vec2 TexPosition;\n"
"uniform sampler2D passTexture;\n" 
...
"   outColor = texture( passTexture, (TexPosition+vec2(1,1))/2);\n"
...
Inside ovrRenderer_RenderFrame
...
GL( glActiveTexture(GL_TEXTURE0));
GL( glBindTexture(GL_TEXTURE_2D, texture1));
...
Is there something wrong? Any help would be much appreciated! ❤️
Thank You! 



0 REPLIES 0