Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
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  
  Slick2D image problem  (Read 1017 times)
0 Members and 1 Guest are viewing this topic.
Offline Xemdo

Senior Newbie


Medals: 1
Exp: 2 years



« Posted 2012-10-29 22:08:06 »

For some reason images keep looking... strange...
Here is what it looks like:

The actual image I am attempting to display is this:


I am new to OpenGL, so I have no idea why this isn't working. I am using code similar to what is found on the LWJGL wiki.

My current code is this:
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  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
package com.szanto.game;

import static org.lwjgl.opengl.GL11.*;
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class Game {
   public static void main(String args[]) {
      new Game().run();
   }
   
   public final int WINDOW_WIDTH = 640, WINDOW_HEIGHT = 480;
   private long lastFPSTime;
   private int fpsCounter;
   private Texture texture;
   
   public void run() {
      try {
         Display.setDisplayMode(new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT));
         Display.setTitle("Game");
         Display.create();
      } catch (LWJGLException e) {
         e.printStackTrace();
         System.exit(0);
      }
     
      init();
      this.lastFPSTime = System.currentTimeMillis();
     
      while (!Display.isCloseRequested()) {
         glClear(GL_COLOR_BUFFER_BIT);
         
         renderGame();
         
         Display.update();
         Display.sync(60);
         calculateFPS();
      }
     
      Display.destroy();
   }
   
   private void init() {
      // Init OpenGL
     glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      glOrtho(0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, 1, -1);
      glMatrixMode(GL_MODELVIEW);
      glEnable(GL_TEXTURE_2D);
      glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     
      // Init Other
     try {
         this.texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/image.png"));
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
   
   private void renderGame() {
      this.texture.bind();
     
      glBegin(GL_QUADS);
         glTexCoord2f(1, 1);
         glVertex2f(30, 30);
         glTexCoord2f(1, 0);
         glVertex2f(30, 10);
         glTexCoord2f(0, 0);
         glVertex2f(10, 10);
         glTexCoord2f(0, 1);
         glVertex2f(10, 30);
      glEnd();
   }
   
   private void calculateFPS() {
      long currentTime = System.currentTimeMillis();
      if (currentTime - this.lastFPSTime > 1000) { this.lastFPSTime = currentTime; Display.setTitle("FPS: " + this.fpsCounter); this.fpsCounter = 0; }
      this.fpsCounter++;
   }
}


I'll love anyone who can help me fix it Smiley
Offline theagentd
« Reply #1 - Posted 2012-10-29 22:26:14 »

Slick2D still lives in 1997 and pads your texture resolution to the closest power of 2. You need to get the ratio of the texture width and height that is actually used by your image and use those as texture coordinates. I've forgotten exactly what the name is of the function, but it's gettable from your Texture instance.

Myomyomyo.
Offline davedes
« Reply #2 - Posted 2012-10-29 23:00:21 »

See here:
http://slick.javaunlimited.net/viewtopic.php?p=25911#p25911

Surprisingly, LibGDX also doesn't accept NPOT textures on desktop if useGL20 is set to false, even if it's available in hardware.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 200



« Reply #3 - Posted 2012-10-31 18:39:26 »

I believe GLES 1.x doesn't support NPOT textures, that's why.  LibGDX understandably has a bit of a lowest-common-denominator thing going on there.

Offline davedes
« Reply #4 - Posted 2012-10-31 20:38:59 »

Understandable, but LibGDX is now one of the better APIs for 2D game development on desktop (and I would argue perhaps 3D as well, because of the added bonus of WebGL/Android/iOS backends). It needs to start embracing some desktop features like closeRequested, vsync, hardware mouse cursors, NPOT textures, geometry shaders, and other desktop-specific things. Since the devs are obviously busy with other things, hopefully I'll find some time to throw in some pull requests this weekend. Smiley

Offline Nate

JGO Kernel


Medals: 129
Projects: 3
Exp: 14 years


Esoteric Software


« Reply #5 - Posted 2012-11-01 00:38:41 »

Surprisingly, LibGDX also doesn't accept NPOT textures on desktop if useGL20 is set to false, even if it's available in hardware.
Use Texture.setEnforcePotImages(false);.

It needs to start embracing some desktop features like closeRequested, vsync, hardware mouse cursors, NPOT textures, geometry shaders, and other desktop-specific things.
LwjglFrame gives you Swing features to get some of these things. Otherwise you can use LWJGL directly or blame LWJGL for lacking features. Smiley Of course, cross platform contributions are always super welcome!

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.

xsi3rr4x (75 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!