Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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  
  Is there any way to draw images from files without  (Read 2652 times)
0 Members and 1 Guest are viewing this topic.
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Posted 2004-01-11 12:39:07 »

reverting to sill swing/awt libs?

This is seriously getting on my nerves, the amount ot tutorials that don't help me with this are enourmous. I've spent hours trying to find alternatives to awt/swing image rendering.

I can render silly shapes with several colours and have them all move in strange directions, but I can't seem to be able to load images in LWJGL. I never had any trouble doing this on an applet, so why is it so difficult under GL?

Second of all, why doesn't Keyboard.key do anything?

Thanks

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline tom
« Reply #1 - Posted 2004-01-11 13:18:11 »

You can use swing/awt to load you images. Create a BufferedImage and use getRGB to fetch the data. You'll need to send the image data to opengl as an array of ints.

Or you could use an independant image loader. There is a tga loader in the Shaven Puppy Game Library:
http://cvs.sourceforge.net/viewcvs.py/spgl/spgl-tools/src/com/shavenpuppy/jglib/tools/

Keyboard.key is used when keyboard buffering is enabled.

Offline renanse

Junior Devvie


Exp: 14 years


Intelligence is light to a dark world.


« Reply #2 - Posted 2004-01-11 13:31:28 »

Quote
Second of all, why doesn't Keyboard.key do anything?

Use Keyboard.poll(), then call Keyboard.isKeyDown(Keyboard.KEY_XXXX) to determine if that key was down when you called .poll().

Renanse  (ruh-NON-say)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2004-01-11 13:37:26 »

Nehe lesson 6 handles texture mapping. It shows you a way to load images into opengl. The nehe lessons can be downloaded here:
http://sourceforge.net/project/showfiles.php?group_id=58488

Offline Mr_Ridd

Senior Newbie




Java games rock!


« Reply #4 - Posted 2004-01-12 05:54:57 »

private final static int loadTexture(String path)
{
           Image image = (new javax.swing.ImageIcon(path)).getImage();

             // Extract The Image
           BufferedImage tex = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_3BYTE_BGR);
           Graphics2D g = (Graphics2D) tex.getGraphics();
           g.drawImage(image, null, null);
           g.dispose();

             // Flip Image
           AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
           tx.translate(0, -image.getHeight(null));
           AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
           tex = op.filter(tex, null);

             // Put Image In Memory
           ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getWidth() * tex.getHeight());

           byte data[] = (byte[]) tex.getRaster().getDataElements(0, 0, tex.getWidth(), tex.getHeight(), null);
           scratch.clear();
           scratch.put(data);
           scratch.rewind();

             // Create A IntBuffer For Image Address In Memory    
           IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();

           GL.glGenTextures(buf); // Create Texture In OpenGL    

           GL.glBindTexture(GL.GL_TEXTURE_2D, buf.get(0)); // Typical Texture Generation Using Data From The Image

             // Linear Filtering
           GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
           GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);

             // Generate The Texture
           GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, scratch);

           return buf.get(0); // Return Image Address In Memory
}

I'm not sure what the layout will look like because I pasted this.

Ok..
This works for me.
The only thing is that the image/texture HAS to be 256x256 pixels

The way to use it:
   define a variable of type int
      int num = 0;
   when you ini* openGL call the method
     num = loadTexture("path");

Then you can use that 'num' to bind the texture
Offline princec

« JGO Spiffy Duke »


Medals: 973
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2004-01-12 06:26:57 »

You can use any size texture provided that its dimensions are a power-of-two. (Independent of each other), eg. 64x16, 512x512, etc.

Cas Smiley

Offline Mr_Ridd

Senior Newbie




Java games rock!


« Reply #6 - Posted 2004-01-12 06:42:55 »

Cool, I didn't know that. Thanks for the correction.
Offline K.I.L.E.R

Senior Devvie




Java games rock!


« Reply #7 - Posted 2004-01-12 11:31:24 »

Thanks fellas.

Though I am skeptical when it comes down to using Sun's libraries for the buffered image.

Are there alternatives?

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline princec

« JGO Spiffy Duke »


Medals: 973
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #8 - Posted 2004-01-12 13:14:13 »

Code your own proprietry format and preformat your images into this format. That's what I do; saves me quite a bit of download space due to using a slightly better compression algorithm.

Cas Smiley

Offline tom
« Reply #9 - Posted 2004-01-12 13:21:44 »

Found this after some googeling:

imagero: lots of formats supported. Returns java.awt.image.ImageProducer though. So you have to go threw awt anyway.
http://reader.imagero.com/

Formatting Objects Processor: A project that has custom image loaders. Source is available but I haven't looked at it:
http://xml.apache.org/fop/index.html

And there also some kits from sun:
http://java.sun.com/products/jimi/
http://java.sun.com/products/java-media/jai/

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

Senior Devvie


Medals: 1


Who, me?


« Reply #10 - Posted 2004-01-13 10:42:52 »

Writing a Raw TGA, BMP or RGB/SGI image loader is really, really easy.  Grab yourself a copy of the specs and give it a try.  This will free you from dependence on AWT (if that's what you want), and it's educational, too! Grin

Hellomynameis Charlie Dobbie.
Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (108 views)
2017-09-30 02:57:34

theagentd (135 views)
2017-09-26 18:23:31

cybrmynd (245 views)
2017-08-02 12:28:51

cybrmynd (239 views)
2017-08-02 12:19:43

cybrmynd (238 views)
2017-08-02 12:18:09

Sralse (252 views)
2017-07-25 17:13:48

Archive (864 views)
2017-04-27 17:45:51

buddyBro (1007 views)
2017-04-05 03:38:00

CopyableCougar4 (1566 views)
2017-03-24 15:39:42

theagentd (1373 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!