Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (548)
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 2124 times)
0 Members and 1 Guest are viewing this topic.
Offline Vage

Senior Newbie




learning++;


« Posted 2005-11-20 15: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: 2


pixels! :x


« Reply #1 - Posted 2005-11-20 16: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 16: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
Offline princec

JGO Kernel


Medals: 362
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2005-11-21 09: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 10: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: 2


pixels! :x


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

* oNyx points at guess #2

Told ya Tongue Wink

弾幕 ☆ @mahonnaiseblog
Offline colesbury

Senior Newbie





« Reply #6 - Posted 2005-11-22 01: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 18: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.

 

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

The first screenshot will be displayed as a thumbnail.

atombrot (27 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!