From: Alban C. <aco...@mi...> - 2002-03-07 09:21:13
|
>Hello, > I'm looking at some of the demo code, but i'm not entirely sure >how to go from the exert below to loading in and binding the three >textures i require in the loadtextures method, do we have to delete >the >image after we are finished. >If there is an easier way to load in 3 textures, could someone please >let me know. >The loading in part seems to be the most difficult part. > >Thanks again, > Mark. Sure, it is possible. When you load your textures, you are storing them in the array object texture[]. So basically, what you have to do is repeat the operation for each texture, binding a different texture slot each time. Here is some code that should work and generate 3 mipmapped textures : int[] texture = new int[3]; //Storage for 3 textures string[] texturePaths = new String[3]; texturePaths[0]="pic/crate.png"; texturePaths[1]="pic/crate2.png"; texturePaths[2]="pic/crate3.png"; init(){ gl.glGenTextures(3, texture); //initialise the 3 texture slots for(int i=0; i<3; i++) { PngTextureLoader texLoader = new PngTextureLoader(gl,glu); texLoader.readTexture(getCodeBase(), texturePaths[i]); if(texLoader.isOk()) { //there you store the texture in slot i ... gl.glBindTexture(GL_TEXTURE_2D, texture[i]); //... and then specify the parameters gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR); gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR); glu.gluBuild2DMipmaps(gl.GL_TEXTURE_2D, 3, texLoader.getImageWidth(), texLoader.getImageHeight(), texLoader.getGLFormat(), gl.GL_UNSIGNED_BYTE, texLoader.getTexture()); } } display(){ //there you select the texture you want to display int index = 0; //or 1 or 2 according to the texture you want to display gl.glBindTexture(gl.GL_TEXTURE_2D, texture[index]); //code to draw your object goes here gl.glBegin(); //(...) gl.glEnd(); } |