Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2] 3 4
  ignore  |  Print  
  So you like Textures eh? Texturing Demo in JOGL.  (Read 21011 times)
0 Members and 1 Guest are viewing this topic.
Offline kevglass

« JGO Spiffy Duke »


Medals: 195
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #30 - Posted 2003-07-22 18:26:37 »

I still can't get this to work, my textures just don't show up. XP, ATI graphics card.

However, I noticed above that Ant? couldn't get the INT format to work even once you've added the creation of the buffer.

You need to multiply the size of the buffer (data.length) by the size of an int, in the JOGL demo this is :

BufferUtils.SIZEOF_INT

However, I'd appreciate any suggestions..

Kev

Offline aNt

Senior Devvie




AFK


« Reply #31 - Posted 2003-07-22 18:29:16 »



QTTexture.java and here the magic bit. looks simple dont it :). always is. i think it can be opimized a lot, but heres your music and video. also loads any quicktime media types. bmp, tga, jpg, gif, png, mov, mp4, mp3, mpg, interactive quicktime, streaming media, and load loads more.. even smil :)



package ant.games.texture;

import java.awt.*;
import java.awt.image.*;

import quicktime.*;
import quicktime.app.view.*; // New QTJava
import quicktime.io.*;
import quicktime.qd.*;
import quicktime.std.*;
import quicktime.std.movies.*;
import quicktime.std.movies.media.*;

public class QTTexture {
 private boolean mov_loaded;
 private DataRef qdr;
 private Movie mov;
 private MoviePlayer mp;
 private int kwidth = 32;
 private int kheight = 32;

 public QTTexture(String file, int width, int height) {
   this.mov_loaded = false;
   this.kwidth = width;
   this.kheight = height;

   try {
     QTSession.open();
   }
   catch (Exception ex) {
     System.out.println("cant open quicktime");
   }

   try {
     qdr = new DataRef(new QTFile(file));
     mov = Movie.fromDataRef(qdr, StdQTConstants.newMovieActive);
     mov.getTimeBase().setFlags(StdQTConstants.loopTimeBase); // QTJava new version.
     // MovieController mc = new MovieController(mov); // Use for old QTJava
     // mc.setLooping(true); // Use for old QTJava
     mp = new MoviePlayer(mov);
     mp.setRate(1f);
     mov_loaded = true;
   }
   catch (Exception ex) {
     System.out.println("cant play quicktime: " + ex.toString());
   }
 }

 public BufferedImage getQT2BufferedImage() {
   try {
     if (mov_loaded) {
       QDRect r = new QDRect(kwidth, kheight);
       Dimension imageSize = new Dimension(r.getWidth(), r.getHeight());
       QTImageProducer qtProducer = new QTImageProducer(mp, imageSize);
       Image javaImage = Toolkit.getDefaultToolkit().createImage(qtProducer);
       BufferedImage bi = new BufferedImage(r.getWidth(), r.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
       Graphics bg = bi.getGraphics();
       bg.drawImage(javaImage, 0, kheight, kwidth, -kheight, null);
       bg.dispose();
       return (bi);
     } else {
       System.out.println("cant find texture: " + qdr.toString());
     }
     return (null);
   }
   catch (Exception ex) {
     System.out.println("cant get texture: " + ex.toString());
     return (null);
   }
 }
}
Offline aNt

Senior Devvie




AFK


« Reply #32 - Posted 2003-07-22 18:31:19 »

and thats it.. a fully working QTTexture loader for JOGL Smiley works cool on MacOSX and WindowsXP here...

hope it helps Smiley - oh and the Texture.java etc is from the java alreay here. i didnt have to change that at all Smiley top result
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tortoise

Junior Devvie




<3 Shmups


« Reply #33 - Posted 2003-07-22 18:58:13 »

Very nice. Thank you. No Linux QT is disappointing but I'll still take it.
Offline kevglass

« JGO Spiffy Duke »


Medals: 195
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #34 - Posted 2003-07-22 19:18:17 »

Got it all working, wahay!

Even got it handling ALPHA channels in PNG images.

Wahey!

Kev

Offline gregorypierce

Senior Devvie




I come upon thee like the blue screen of death....


« Reply #35 - Posted 2003-07-23 03:18:48 »

Hey Ken you know the deal, post up your changes for dealing with your Alpha types. I have it working but not with all .png files and I'm trying to solve that problem before I post up the latest version. I'm also adding the QuickTime code to the core code and finishing up for the multitexture demo - also gives a demo on fonts 'for free'.

http://www.gregorypierce.com

She builds, she builds oh man
When she links, she links I go crazy
Cause she looks like good code but she's really a hack
I think I'll run upstairs and grab a snack!
Offline kevglass

« JGO Spiffy Duke »


Medals: 195
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #36 - Posted 2003-07-23 04:09:54 »

That'd be Kev...

I'll post source as soon as I can get my hands on it (I'm at work now, source is at home).

However, essentially the problem to me seems to be driving srcPixelFormat from the user's request. The srcPixelFormat should be based on the image.

All I did was add a bufferedImage.getColorModel().hasAlpha() check and change the src pixel format to GL.GL_RGBA. Of course, you had to pass in a destPixelFormat of GL.GL_RGBA, otherwise the alpha gets stripped straight out.

I had this idea on the way in this morning, for coping with all images types. How about creating a buffered image of type INT_ARGB or INT_RGB depending on what you want to use. Then load the texture image and draw it into your precreated image using getGraphics().drawImage(). Then process the buffer into a texture. All oddities of image format should be handled then since the original draw will convert the image to the right type. Would this work?

Kev

8: Undefined index: online
File: /home/jgo/public_html/Themes/default/Display.template.php (main sub template - eval?)
Line: 161