From: Mark M. <pat...@lm...> - 2003-03-21 20:11:01
|
All, Follow up texture-mapping questions... First, I fixed my original problem that was causing textures in my application to be all white. I had a special initialization method to set all the texture mapping parameters. I forgot to surround those GL calls with: glc.getGLContext().gljMakeCurrent(); AND glc.getGLContext().gljFree(); A rather newbie-sounding mistake, but it's been a while since I wrote rendering code in GL4Java. I hate that you have to perform those steps in the non-draw methods, but I realize it is a necessary evil (Magician had the same thing). On to my 2 new questions (somewhat more advanced): (Q1) I am loading fairly large textures of satellite imagery of the Earth. Two of them are 1024x1024 (powers of two) in RGB format. These two images load and render just fine. The third texture is 2048x1024 (also powers of two) in RGB format. This one gets a GL error during my call to glTexImage2d(), and the error is "invalid value." I determined that value that makes it unhappy is the image width (2048). If I lie to OpenGL and tell it that the width is only1024, the image loads and renders without an error (of course it looks screwed up, but I expect that since I lied about the true width). Any insight on why it cannot handle the 2048 width? I know that it is not related to the hardware, graphics card, graphics card driver, or machine configuration. I know this because our application is half GL4Java and half Java3D. The Java3D display loads the same exact textures and renders them with no problem. I also do not think it is related to the total amount of texture memory available; again because Java3D has no problem, and I can disable the Java3D display and disable to two 1024x1024 textures in the GL4Java display...and the GL4Java display still gets the same error on the 2048x1024 texture. Could it have something to do with the OpenGL context or configuration that I am requesting??? Could it be related to the fact that I am using display-lists??? [[ I inserted my texture mapping method at the bottom of this message. ]] (Q2) My textures are rendered in a 2D display, no lighting, no normals, no materials. The polygons underneath the texture are white. The texture comes out way to dark with GL_DECAL or GL_REPLACE. When I try GL_MODULATE or GL_BLEND, it gets really washed-out. We had this same exact problem in the Java3D display with these textures. We fixed it there by using some texture-environment settings that are unique to Java3D. (In other words, the Java3D people used some of the more advanced features of blending functions and/or filters to create a new blending equation that works well.) I was considering a decompile of the Java3D code to see how they did it, but I thought I would as for some advice on this problem first. ---------------------------------------------------------------------------------------- My texture map initialization code (sorry for the formatting if your mail tool doesn't support fixed-width fonts): private void initialize() { // Must make the GLComponent's OpenGL context current when outside a // GLEventListener callback method. Then don't forget to unlock() it. glc.getGLContext().gljMakeCurrent(); // Make current to call OpenGL GeoTiffImage image = geoTiffDef.getGeoTiffImage(); Raster raster = image.getAsRaster(); Object data = raster.getDataElements( 0, 0, raster.getWidth(), raster.getHeight(), null ); if( ToolkitConstants.TK_DEBUG_PATCH2D == true ) { if( raster.getTransferType() == DataBuffer.TYPE_BYTE ) System.out.println( "Texture storage type = TYPE_BYTE"); else { System.err.println( "TexturedPatch2d.initialize() - " + "What is the texture storage type?"); System.err.flush(); } System.out.println( "Num data elements = " + raster.getNumDataElements() ); System.out.println( "Geotiff size = (" + raster.getWidth() + ", " + raster.getHeight() + ")" ); } // Set unpacking to use 1 byte allignment gl_.glPixelStorei( GLEnum.GL_UNPACK_ALIGNMENT, 1 ); // Ask for valid, unused texture name gl_.glGenTextures( 1, textureName ); // Bind a texture object to the name gl_.glBindTexture( GLEnum.GL_TEXTURE_2D, textureName[0] ); // Set clamping preferences gl_.glTexParameteri( GLEnum.GL_TEXTURE_2D, GLEnum.GL_TEXTURE_WRAP_S, GLEnum.GL_CLAMP ); gl_.glTexParameteri( GLEnum.GL_TEXTURE_2D, GLEnum.GL_TEXTURE_WRAP_T, GLEnum.GL_CLAMP ); // Set mag and min filter preferences gl_.glTexParameteri( GLEnum.GL_TEXTURE_2D, GLEnum.GL_TEXTURE_MAG_FILTER, GLEnum.GL_NEAREST ); gl_.glTexParameteri( GLEnum.GL_TEXTURE_2D, GLEnum.GL_TEXTURE_MIN_FILTER, GLEnum.GL_NEAREST ); gl_.glTexEnvi( GLEnum.GL_TEXTURE_ENV, GLEnum.GL_TEXTURE_ENV_MODE, GLEnum.GL_MODULATE ); // GL_REPLACE, GL_BLEND, GL_DECAL gl_.glHint( GLEnum.GL_PERSPECTIVE_CORRECTION_HINT, GLEnum.GL_FASTEST ); // Define the 2D texture gl_.glTexImage2D( GLEnum.GL_TEXTURE_2D, 0, GLEnum.GL_RGB, raster.getWidth()/2, raster.getHeight(), 0, GLEnum.GL_RGB, GLEnum.GL_UNSIGNED_BYTE, (byte[]) data ); if( ToolkitConstants.TK_DEBUG_PATCH2D == true ) { int errorCode = GLEnum.GL_NO_ERROR; if( (errorCode = gl_.glGetError()) != GLEnum.GL_NO_ERROR ) { System.err.println( "TexturedPatch2d.initialize() - " + "GL Error: " + glu_.gluErrorString(errorCode) ); System.err.flush(); } } glc.getGLContext().gljFree(); // Must unlock OpenGL context } private void constructDisplayList() { destroyDisplayList(); // Must make the GLComponent's OpenGL context current when outside a // GLEventListener callback method. Then don't forget to unlock() it. glc.getGLContext().gljMakeCurrent(); // Make current to call OpenGL displayListId = gl_.glGenLists( 1 ); // Ask OpenGL for a unique Id if( displayListId > 0 ) { gl_.glNewList( displayListId, GLEnum.GL_COMPILE ); renderGeometry(); gl_.glEndList(); } else { isValidPatch = false; System.err.println( "TexturedPatch2d.constructDisplayList() - " + "can't generate a valid display list Id: " + displayListId + "\n" ); } glc.getGLContext().gljFree(); // Must unlock OpenGL context } Mark Montana wrote: > I got a few responses to my texture mapping question, so I thought I would > address them all at once. > > -First let me say thank you for the references and the example code for > texture mapping. > > -I was looking for GL4Java code, and I got a good example. Thanks William. > > -I already thought that someone would ask me to post my code. Unfortunately > our total application is fairly big (~30,000 lines), so I would have to take > some real time to carve out a reasonably sized piece which exhibits the > behavior. However, if I continue to have trouble, I guess I could submit a > code snippet that does not run, but shows my design. > > -Since my original posting, I noticed that all texture mapping examples in > GL4Java were showing as pure white textures on my machine (Dual Pentium 4, > with Wildcat III 6110). But other PCs in the office were running the texture > mapping examples just fine. Our application still shows as pure white on ALL > machines. Something is still wrong with my code, and I'm about to look into > that now. > > -I was sent a GL4Java example that showed some brick textures, and > surprisingly, that worked on all our machines, including the Wildcat III 6110. > Go figure! ;-) > > Thanks again. > > ------------------------------------------------------- > This SF.net email is sponsored by: Tablet PC. > Does your code think in ink? You could win a Tablet PC. > Get a free Tablet PC hat just for playing. What are you waiting for? > http://ads.sourceforge.net/cgi-bin/redirect.pl?micr5043en > _______________________________________________ > gl4java-usergroup mailing list > gl4...@li... > https://lists.sourceforge.net/lists/listinfo/gl4java-usergroup |