Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  32-bit Graphics, getting dithered down to 16-bit?  (Read 1731 times)
0 Members and 1 Guest are viewing this topic.
Offline Vage

Senior Newbie




learning++;


« Posted 2005-11-20 16:56:21 »

Hey guys, I just recently made the switch to LWJGL from Java2D and I have to say I love it Smiley

Anyway, I'm having a slight problem: My 32-bit graphics are getting dithered down to 16-bit, and then being displayed on my 32-bit screen. Argh! Any ideas?

Example:


I'll try to post any relevent code blocks as well:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
   public static QTexture fromFile( String name, boolean flip )
   {
      QTexture texture = null;
      ByteBuffer imageData = null;
      int ilImageHandle;
      int oglImageHandle;
      IntBuffer scratch = BufferUtils.createIntBuffer(1);
     
      try{
         IL.create();
         ILU.create();
         ILUT.create();
      } catch (LWJGLException ex) {
         
      }
      // create image in DevIL and bind it
     IL.ilGenImages(scratch);
      IL.ilBindImage(scratch.get(0));
      ilImageHandle = scratch.get(0);
     
      // load the image
     if( !IL.ilLoadImage( name ) )
         return null;
     
      // convert image to RGBA
     IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
     
      // flip
     if( flip )
         ILU.iluFlipImage();
     
      // get image attributes
     int width = IL.ilGetInteger(IL.IL_IMAGE_WIDTH);
      int height = IL.ilGetInteger(IL.IL_IMAGE_HEIGHT);
      int textureWidth = QUtil.getNextPowerOfTwo(width);
      int textureHeight = QUtil.getNextPowerOfTwo(height);
     
      // resize image according to poweroftwo
     if (textureWidth != width || textureHeight != height)
      {
         imageData = BufferUtils.createByteBuffer(textureWidth * textureHeight * 4);
         IL.ilCopyPixels(0, 0, 0, textureWidth, textureHeight, 1, IL.IL_RGBA, IL.IL_BYTE, imageData);
      }
      else
         imageData = IL.ilGetData();
     
      // create OpenGL counterpart
     GL11.glGenTextures(scratch);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, scratch.get(0));
      oglImageHandle = scratch.get(0);
     
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
      GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, textureWidth, textureHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, imageData);
     
      // Create image (either resized by copying, else directly from IL)
     if (textureWidth != width || textureHeight != height)
         texture = new QTexture(oglImageHandle, width, height, (width / (float) textureWidth), (height / (float) textureHeight), textureWidth, textureHeight);
      else
         texture = new QTexture(oglImageHandle, width, height);
     
      // delete Image in DevIL
     scratch.put(0, ilImageHandle);
      IL.ilDeleteImages(scratch);
      IL.destroy();
      ILU.destroy();
      ILUT.destroy();
     
      // revert the gl state back to the default so that accidental texture binding doesn't occur
     GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
     
      // return OpenGL texture handle
     return texture;
   }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
   public static void drawImage( QTexture tex, int x, int y )
   {
      if( color[3] == 0 )
         return;
      // store the current model matrix
     GL11.glPushMatrix();
     
      // translate to the right location and prepare to draw
     GL11.glTranslatef(x, y, 0);
      GL11.glColor4f( color[0], color[1], color[2], color[3] );

      if( ra != 0 && ra != 360 )
      {
         float rx1 = rx - x;
         float ry1 = ry - y;
         GL11.glTranslatef(rx1, ry1, 0);
         GL11.glRotatef( ra, 0, 0, 1 );
         GL11.glTranslatef(-rx1, -ry1, 0);
      }
      GL11.glEnable(GL11.GL_TEXTURE_2D);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureId() );
      GL11.glBegin(GL11.GL_QUADS);
      {
         GL11.glTexCoord2f( 0, 0 );
         GL11.glVertex2f( 0, 0 );
         
         GL11.glTexCoord2f( tex.getWidthRatio(), 0 );
         GL11.glVertex2f( tex.getWidth(), 0 );
         
         GL11.glTexCoord2f( tex.getWidthRatio(), tex.getHeightRatio() );
         GL11.glVertex2f( tex.getWidth(), tex.getHeight() );
         
         GL11.glTexCoord2f( 0, tex.getHeightRatio() );
         GL11.glVertex2f( 0, tex.getHeight() );
      }
      GL11.glEnd();
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0 );
      GL11.glDisable(GL11.GL_TEXTURE_2D);
      // restore the model view matrix to prevent contamination
     GL11.glPopMatrix();
   }

Personally, you could strap me into a mech cockpit with 47 virtual HUD displays, two complex hand controls and foot pedals and I'd be grinning like the gamer freak I am.
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #1 - Posted 2005-11-20 17:10:02 »

Guess#1

IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE); <- Remove that line.

Btw you can resample a texture with ILU.iluScale(new_width, new_height, IL.ilGetInteger(IL.IL_IMAGE_DEPTH)) and you get the best quality with ILU.iluImageParameter(ILU.ILU_FILTER, ILU.ILU_SCALE_LANCZOS3).

Guess#2

Check the driver settings.

弾幕 ☆ @mahonnaiseblog
Offline Vage

Senior Newbie




learning++;


« Reply #2 - Posted 2005-11-20 17:53:00 »

Hmm, no such luck. I tried both suggestions, reinstalled nVidia drivers as well.
Well, it's not a big deal; But if you guys have any other guesses, please throw 'em at me Smiley Thanks anyway!

If I ever find the issue I'll post it here for reference.

Personally, you could strap me into a mech cockpit with 47 virtual HUD displays, two complex hand controls and foot pedals and I'd be grinning like the gamer freak I am.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #3 - Posted 2005-11-21 10:47:29 »

Nvidia does have a setting to force textures into 16 bit in the display control panel.
And are you sure you've got a 32bpp context? System.out.println(Display.getDisplayMode()) to be sure, after creation.

Cas Smiley

Offline Vage

Senior Newbie




learning++;


« Reply #4 - Posted 2005-11-21 11:23:20 »

EDIT:

Wow, I blame nVidia totally =D

I changed some driver settings, namely 'Image Quality' Smiley, and it magically works. Thanks for that recommendation!

Personally, you could strap me into a mech cockpit with 47 virtual HUD displays, two complex hand controls and foot pedals and I'd be grinning like the gamer freak I am.
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #5 - Posted 2005-11-21 12:25:33 »

* oNyx points at guess #2

Told ya Tongue Wink

弾幕 ☆ @mahonnaiseblog
Offline colesbury

Senior Newbie





« Reply #6 - Posted 2005-11-22 02:25:11 »

I think the command ilutEnable(ILUT_OPENGL_CONV); may force nVidia cards to use correct texture format.

See the entry on ILUT_OPENGL_CONV in http://openil.sourceforge.net/tuts/tut_10/

-Sam
Offline Vage

Senior Newbie




learning++;


« Reply #7 - Posted 2005-11-22 19:04:25 »

Interesting, although I wouldn't want to disable anything on their hardware, so I'll leave it how it is now. Thanks though Wink

Personally, you could strap me into a mech cockpit with 47 virtual HUD displays, two complex hand controls and foot pedals and I'd be grinning like the gamer freak I am.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (78 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (122 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (157 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (179 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.27 seconds with 21 queries.