/// // Load texture from disk // GLuint LoadTexture ( char *fileName ) { int width, height; char *buffer = esLoadTGA ( fileName, &width, &height ); GLuint texId; if ( buffer == NULL ) { esLogMessage ( "Error loading (%s) image.\n", fileName ); return 0; } glGenTextures ( 1, &texId ); glBindTexture ( GL_TEXTURE_2D, texId ); glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); free ( buffer ); return texId; }
GLuint create2DTexture(const char* filename, int width, int height, GLint internalFormat, GLenum type, bool inAssetFolder) { GLuint texId; char* pixels; int w, h; ALOGD("create2DTexture - �뜲�씠�꽣 濡쒕뵫 �떆�옉."); pixels = esLoadTGA(AssetManager::getInstance()->getContext(), filename, &w, &h); ALOGD("create2DTexture - �뜲�씠�꽣 濡쒕뵫 �셿猷�."); glGenTextures(1, &texId); glBindTexture(GL_TEXTURE_2D, texId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, w, h, 0, type, GL_UNSIGNED_BYTE, pixels); ALOGD("create2DTexture - 2D texture binding �셿猷�"); free(pixels); return texId; }
void C2DTexture::load(char *textureFileLocation) { int width, height, colorDepth; char *buffer = esLoadTGA ( textureFileLocation, &width, &height, &colorDepth ); GLuint texId; if ( buffer == NULL ) { //esLogMessage ( "Error loading (%s) image.\n", textureFileLocation ); exit(1); } glGenTextures ( 1, &texId ); glBindTexture ( GL_TEXTURE_2D, texId ); if(colorDepth == 24) glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer ); else if(colorDepth == 32) glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer ); glGenerateMipmap(GL_TEXTURE_2D); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); free ( buffer ); m_ID = texId; }
/// // Load texture from disk // static GLuint LoadTexture ( char *fileName ) { int width, height; char hasAlpha =0; char *buffer=NULL; GLuint texId; if(strstr(fileName,"tga")!=NULL){ buffer=esLoadTGA ( fileName, &width, &height ); }else if(strstr(fileName,"bmp") !=NULL){ Image *image1; // allocate space for texture we will use image1 = (Image *) malloc(sizeof(Image)); if(esLoadBMP ( fileName, image1 ) == 0) { return 0; } width = image1->sizeX; height = image1->sizeY; buffer=image1->data; }else if(strstr(fileName,"png") !=NULL){ buffer= esLoadPNG(fileName,&width, &height, &hasAlpha); } else if(strstr(fileName,"jpg") !=NULL){ #if 0 texId = SOIL_load_OGL_texture(fileName, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_COMPRESS_TO_DXT); return texId; #endif } if ( buffer == NULL ) { esLogMessage ( "Error loading (%s) image.\n", fileName ); return 0; } glGenTextures ( 1, &texId ); glBindTexture ( GL_TEXTURE_2D, texId ); glTexImage2D ( GL_TEXTURE_2D, 0, hasAlpha ? GL_RGBA : GL_RGB, width, height, 0, hasAlpha ? GL_RGBA : GL_RGB , GL_UNSIGNED_BYTE, buffer); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); free ( buffer ); return texId; }
GLuint cTextureLoadFunct::LoadTexture2D(const char *filename) { GLuint textureId1; int width,height; char *data=esLoadTGA ((char*) filename,&width,&height ); assert(data); glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 ); glGenTextures ( 1, &textureId1 ); glBindTexture ( GL_TEXTURE_2D, textureId1 ); glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB, height, width, 0, GL_RGB, GL_UNSIGNED_BYTE, data ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); delete []data; return textureId1; }
GLuint cTextureLoadFunct::LoadTextureCube(std::fstream &f) { GLuint textureId; char name[512]; f>>name; int width,height; // Generate a texture object glGenTextures ( 1, &textureId ); // Bind the texture object glBindTexture ( GL_TEXTURE_CUBE_MAP, textureId ); char *data=esLoadTGA ((char*) name,&width,&height ); // Load the cube face - Positive X glTexImage2D ( GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, width,height, 0, GL_RGB, GL_UNSIGNED_BYTE, data ); delete []data; f>>name; data=esLoadTGA ((char*) name,&width,&height ); // Load the cube face - Negative X glTexImage2D ( GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, width,height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); delete []data; f>>name; data=esLoadTGA ((char*) name,&width,&height ); // Load the cube face - Positive Y glTexImage2D ( GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, width,height, 0, GL_RGB, GL_UNSIGNED_BYTE, data ); delete []data; f>>name; data=esLoadTGA ((char*) name,&width,&height ); // Load the cube face - Negative Y glTexImage2D ( GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, width,height, 0, GL_RGB, GL_UNSIGNED_BYTE, data ); delete []data; f>>name; data=esLoadTGA ((char*) name,&width,&height ); // Load the cube face - Positive Z glTexImage2D ( GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, width,height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); delete []data; f>>name; data=esLoadTGA ((char*) name,&width,&height ); // Load the cube face - Negative Z glTexImage2D ( GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, width,height, 0, GL_RGB, GL_UNSIGNED_BYTE, data ); delete []data; // Set the filtering mode glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); return textureId; }
int main(int argc, char **argv) { struct fbdemos_scaffold *fbs = 0; fbdemo_init(&fbs); int width = fbs->width; int height = fbs->height; struct pipe_context *pipe = fbs->pipe; /* texture */ int tex_base_width = 0; int tex_base_height = 0; if(argc<2) { printf("Pass path to smoke.tga on command line\n"); exit(1); } uint8_t *tex_buffer = (uint8_t*)esLoadTGA(argv[1], &tex_base_width, &tex_base_height ); if(!tex_buffer) { printf("Could not load texture\n"); exit(1); } struct pipe_resource *tex_resource = fbdemo_create_2d(fbs->screen, PIPE_BIND_SAMPLER_VIEW, PIPE_FORMAT_B8G8R8X8_UNORM, tex_base_width, tex_base_height, 0); printf("Uploading texture (%ix%i)\n", tex_base_width, tex_base_height); uint32_t *temp = malloc(tex_base_width * tex_base_height * 4); etna_convert_r8g8b8_to_b8g8r8x8(temp, tex_buffer, tex_base_width * tex_base_height); etna_pipe_inline_write(pipe, tex_resource, 0, 0, temp, tex_base_width * tex_base_height * 4); free(temp); /* render target resources and surfaces */ struct pipe_resource *rt_resource = fbdemo_create_2d(fbs->screen, PIPE_BIND_RENDER_TARGET, PIPE_FORMAT_B8G8R8X8_UNORM, width, height, 0); struct pipe_resource *z_resource = fbdemo_create_2d(fbs->screen, PIPE_BIND_RENDER_TARGET, PIPE_FORMAT_Z16_UNORM, width, height, 0); /* bind render target to framebuffer */ etna_fb_bind_resource(&fbs->fb, rt_resource); /* surfaces */ struct pipe_surface *cbuf = pipe->create_surface(pipe, rt_resource, &(struct pipe_surface){ .texture = rt_resource, .format = rt_resource->format, .u.tex.level = 0 });
int main(int argc, char **argv) { int rv; int width = 256; int height = 256; fb_info fb; rv = fb_open(0, &fb); if(rv!=0) { exit(1); } width = fb.fb_var.xres; height = fb.fb_var.yres; rv = viv_open(); if(rv!=0) { fprintf(stderr, "Error opening device\n"); exit(1); } printf("Succesfully opened device\n"); etna_ctx *ctx = 0; struct pipe_context *pipe = 0; etna_bswap_buffers *buffers = 0; if(etna_create(&ctx) != ETNA_OK || etna_bswap_create(ctx, &buffers, (etna_set_buffer_cb_t)&fb_set_buffer, (etna_copy_buffer_cb_t)&etna_fb_copy_buffer, &fb) != ETNA_OK || (pipe = etna_new_pipe_context(ctx)) == NULL) { printf("Unable to create etna context\n"); exit(1); } /* textore */ int tex_base_width = 0; int tex_base_height = 0; if(argc<2) { printf("Pass path to smoke.tga on command line\n"); exit(1); } uint8_t *tex_buffer = (uint8_t*)esLoadTGA(argv[1], &tex_base_width, &tex_base_height ); if(!tex_buffer) { printf("Could not load texture\n"); exit(1); } struct pipe_resource *tex_resource = etna_pipe_create_2d(pipe, ETNA_IS_TEXTURE, PIPE_FORMAT_B8G8R8X8_UNORM, tex_base_width, tex_base_height, 0); printf("Uploading texture (%ix%i)\n", tex_base_width, tex_base_height); uint32_t *temp = malloc(tex_base_width * tex_base_height * 4); etna_convert_r8g8b8_to_b8g8r8x8(temp, tex_buffer, tex_base_width * tex_base_height); etna_pipe_inline_write(pipe, tex_resource, 0, 0, temp, tex_base_width * tex_base_height * 4); free(temp); /* render target resources and surfaces */ struct pipe_resource *rt_resource = etna_pipe_create_2d(pipe, ETNA_IS_RENDER_TARGET, PIPE_FORMAT_B8G8R8X8_UNORM, width, height, 0); struct pipe_resource *z_resource = etna_pipe_create_2d(pipe, ETNA_IS_RENDER_TARGET, PIPE_FORMAT_Z16_UNORM, width, height, 0); /* bind render target to framebuffer */ etna_fb_bind_resource(&fb, rt_resource); /* surfaces */ struct pipe_surface *cbuf = pipe->create_surface(pipe, rt_resource, &(struct pipe_surface){ .texture = rt_resource, .format = rt_resource->format, .u.tex.level = 0 });
TGAImage( const char * xPath ) { mData = (GLubyte*)esLoadTGA( xPath, &mW, &mH ); }
Texture::Texture(void) { double tWidth, tHeight; char* buffer ; /*sunTex=SOIL_load_OGL_texture ( "Texture/sun.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); earthTex = SOIL_load_OGL_texture ( "Texture/earth.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); marsTex = SOIL_load_OGL_texture ( "Texture/mars.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); moonTex = SOIL_load_OGL_texture ( "Texture/moon.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); jupiterTex = SOIL_load_OGL_texture ( "Texture/jupiter.tga", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);*/ buffer = esLoadTGA("Texture/sun.tga",&tWidth,&tHeight); glGenTextures (1, &sunTex); glBindTexture ( GL_TEXTURE_2D, sunTex); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tWidth, tHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer); free(buffer); buffer = esLoadTGA("Texture/earth.tga",&tWidth,&tHeight); glGenTextures (1, &earthTex); glBindTexture ( GL_TEXTURE_2D, earthTex); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tWidth, tHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer); free(buffer); buffer = esLoadTGA("Texture/moon.tga",&tWidth,&tHeight); glGenTextures (1, &moonTex); glBindTexture ( GL_TEXTURE_2D, moonTex); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tWidth, tHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer); free(buffer); buffer = esLoadTGA("Texture/mars.tga",&tWidth,&tHeight); glGenTextures (1, &marsTex); glBindTexture ( GL_TEXTURE_2D, marsTex); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tWidth, tHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer); free(buffer); buffer = esLoadTGA("Texture/jupiter.tga",&tWidth,&tHeight); glGenTextures (1, &jupiterTex); glBindTexture ( GL_TEXTURE_2D, jupiterTex); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tWidth, tHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer); free(buffer); }