Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (538)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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 1209 times)
0 Members and 1 Guest are viewing this topic.
Offline Xemdo

Senior Newbie


Medals: 1
Exp: 2 years



« Posted 2012-10-29 21: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
Online theagentd

« JGO Bitwise Duke »


Medals: 365
Projects: 2
Exp: 8 years



« Reply #1 - Posted 2012-10-29 21: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 22: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: 202



« Reply #3 - Posted 2012-10-31 17: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 19: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 Bitwise Duke »


Medals: 158
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #5 - Posted 2012-10-31 23: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.

rwatson462 (29 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (50 views)
2014-12-03 16:27:13

CopyableCougar4 (47 views)
2014-11-29 21:32:03

toopeicgaming1999 (114 views)
2014-11-26 15:22:04

toopeicgaming1999 (102 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!