23 #include <GLES2/gl2ext.h>
26 #include <android/log.h>
28 #define CHANNELS_PER_PIXEL 3
30 #define LOG_TAG "libNative"
31 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
32 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
40 FILE * theFile = fopen(texture,
"r");
44 LOGE(
"Failure to load the texture");
51 glTexImage2D(GL_TEXTURE_2D, level, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, theTexture);
54 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
55 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST);
65 GLushort paddedHeight;
68 GLubyte textureHead[16];
71 FILE * theFile = fopen(texture,
"rb");
75 LOGE(
"Failure to load the texture");
79 fread(textureHead, 16, 1, theFile);
81 paddedWidth = (textureHead[8] << 8) | textureHead[9];
82 paddedHeight = (textureHead[10] << 8) | textureHead[11];
83 width = (textureHead[12] << 8) | textureHead[13];
84 height = (textureHead[14] << 8) | textureHead[15];
86 theTexture = (GLubyte *)malloc(
sizeof(GLubyte) * ((paddedWidth * paddedHeight) >> 1));
87 fread(theTexture, (paddedWidth * paddedHeight) >> 1, 1, theFile);
90 glCompressedTexImage2D(GL_TEXTURE_2D, level,
GL_ETC1_RGB8_OES, width, height, 0, (paddedWidth * paddedHeight) >> 1, theTexture);
93 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
94 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST);
GLint GLsizei GLsizei height
void loadTexture(const char *texture, unsigned int level, unsigned int width, unsigned int height)
Loads a desired texture into memory at an appropriate mipmap level.
void loadCompressedTexture(const char *texture, unsigned int level)
Loads a compressed texture into memory at an appropriate mipmap level.
#define CHANNELS_PER_PIXEL
GLenum GLuint GLint level