Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
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 20873 times)
0 Members and 1 Guest are viewing this topic.
Offline Java Cool Dude

Senior Duke




Java forever


« Reply #60 - Posted 2003-08-03 04:39:34 »

Hey.
I got the texture code to work in the port of my collisions_demo from java3d to opengl, however the colors seem to be a bit wrong.
Here's a snap that would help you understand what I'm talking about
http://www.realityflux.com/abba/weird.jpg

original
http://www.realityflux.com/abba/collisions.jpg

I spent a little short of a day doing the port since I've never done opengl before (woah some complicated stuff there  Huh, but I'll get through it Grin), and I love it to pieces, JOGL that is Smiley.
PS: the jogl port runs  about 30-40% faster than java3d Tongue.
Offline kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #61 - Posted 2003-08-03 04:57:50 »

The colours look the same to me on the walls at least. The ground looks to be a different texture all together?

Also, could you not post these big images into the forum, its probably a problem for dial up users and also make the layout go a bit off..

Is the ground the bit that seems to be the problem?

Kev

Offline Java Cool Dude

Senior Duke




Java forever


« Reply #62 - Posted 2003-08-03 05:19:48 »

Nah dude the walls albeit looking similar, you can still notice a tiny difference in between the stones (it looks a bit brownish rather than grey).
The floor is a totally different texture, but take a closer look at the cylinders; I'm positive you'll see that the difference in between the j3d and jogl rendering is obvious.
Any help on that?
PS; the textures are in jpg format, lemmie go check with png Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #63 - Posted 2003-08-03 05:24:35 »

Yeah, actually see what you mean with the "logs". Maybe it something to do with lighting? The way the texture loaded works (as I remember) is to ask java in 2d to convert from whatever image you specify into something Jogl can handle.. so I suppose if there is a problem, it might be worth looking at the images created in the conversion routine: convertImageData

I've been using GIF and PNG files and haven't noticed any problems (and I'm working in 2D, so they'd be bleady obvious Wink)

Kev

PS. Thanks for changing those images to links, very community spirited of ya. Smiley

Offline epotash

Senior Newbie




Java games rock!


« Reply #64 - Posted 2003-08-03 05:37:57 »

Troggan: Your application ran fine for me, i got 2 fps, but what do you expect from a 2mb card...

here is the code for my TextureDemo, it is just a rotating cube with some basic lighting... run "java TextureDemo " + the filename of any texture.  You will need the Texture and TextureLoader classes shown earlier, but i didnt use the original package names so you may need to import them...
The frame rate will be displayed in the console, i would like to know what you get... it should pretty much be vsync capped for any decent card.

Quote

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;

import net.java.games.jogl.*;

public class TextureDemo {
 public static void main(String[] args) {
   Frame frame = new Frame("Texture Demo");
   GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());

   canvas.addGLEventListener(new TextureRenderer(args[0]));
   frame.add(canvas);
   frame.setSize(640, 480);
   final Animator animator = new Animator(canvas);
   frame.addWindowListener(new WindowAdapter() {
     public void windowClosing(WindowEvent e) {
       animator.stop();
       System.out.println();
       System.exit(0);
     }
   });
   animator.start();
   frame.show();
 }

 static class TextureRenderer
     implements GLEventListener {

   private GL gl;
   private GLU glu;
   private GLDrawable gldrawable;
   private TextureLoader texloader;
   private Texture texture;

   private float xrot, yrot, xspeed = 1, yspeed = 1,
                 z = -20.0f;
   private float[] ambient  = { 0.5f, 0.5f, 0.5f, 1.0f };
   private float[] diffuse  = { 1.0f, 1.0f, 1.0f, 1.0f };
   private float[] position = { 0.0f, 0.0f, 2.0f, 1.0f };

   private String resource;
   private int f;
   private long t1 , t2;

   public TextureRenderer(String resource) {
     this.resource = resource;
   }  

   public void init(GLDrawable drawable) {
     gl = drawable.getGL();
     this.gldrawable = drawable;

     gl.glEnable(GL.GL_TEXTURE_2D);
     gl.glShadeModel(GL.GL_SMOOTH);
     gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     gl.glEnable(GL.GL_DEPTH_TEST);
     gl.glDepthFunc(GL.GL_LEQUAL);
     gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
     gl.glEnable(GL.GL_LIGHT1);

     gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, diffuse);
     gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, position);
     gl.glEnable(GL.GL_LIGHTING);
     try {
       texloader = new TextureLoader(gl, glu);
       texture = texloader.getTexture("texture01", resource);
     } catch (IOException e) { }
   
     t1 = System.currentTimeMillis();
   }
   
   public void reshape(GLDrawable drawable, int x, int y, int width, int height) {
     float h = (float)height / (float)width;
     gl.glMatrixMode(GL.GL_PROJECTION);

     gl.glLoadIdentity();
     gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 100.0f);
     gl.glMatrixMode(GL.GL_MODELVIEW);
     gl.glLoadIdentity();
     gl.glTranslatef(0.0f, 0.0f, -50.0f);
   }

   public void display(GLDrawable drawable) {
     f++;
     t2 = System.currentTimeMillis();
     if (t2 - t1 > 500) {
       float fps = (int)((float)f / (t2 - t1) * 10000)/10f;
       System.out.print( (char)13 + "" + fps + "fps" + '\t');
       f = 0;
       t1 = t2;
     }
     gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
     
     gl.glLoadIdentity();
     gl.glTranslatef(0.0f, 0.0f, z);

     gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f);
     gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f);

     texture.bind(gl);
     gl.glBegin(GL.GL_QUADS);
       // Front Face
       gl.glNormal3f( 0.0f, 0.0f, 1.0f);
       gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);
       gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);
       gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);
       gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);
       // Back Face
       gl.glNormal3f( 0.0f, 0.0f,-1.0f);
       gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);
       gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);
       gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);
       gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);
       // Top Face
       gl.glNormal3f( 0.0f, 1.0f, 0.0f);
       gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);
       gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);
       gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);
       gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);
       // Bottom Face
       gl.glNormal3f( 0.0f,-1.0f, 0.0f);
       gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);
       gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);
       gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);
       gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);
       // Right face
       gl.glNormal3f( 1.0f, 0.0f, 0.0f);
       gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f, -1.0f);
       gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f, -1.0f);
       gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f( 1.0f,  1.0f,  1.0f);
       gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f( 1.0f, -1.0f,  1.0f);
     // Left Face
       gl.glNormal3f(-1.0f, 0.0f, 0.0f);
       gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f);
       gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f,  1.0f);
       gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f,  1.0f);
       gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f,  1.0f, -1.0f);
     gl.glEnd();

     xrot += xspeed;
     yrot += yspeed;
   }

   public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
 }
}
Offline Java Cool Dude

Senior Duke




Java forever


« Reply #65 - Posted 2003-08-03 05:47:37 »

W00t just as I suspected; saving the images as png instead of jpg solved the problem.
I also noticed a very bizarre thing: check this screenshot out and tell me if it's just my eyes going nuts at 3.46 in the morning or the frame rate almost doubled?  Shocked
http://www.realityflux.com/abba/w00t.jpg
It's at least twice as fast as what j3d was giving me framerate wise
/me hugs jogl Grin
Offline epotash

Senior Newbie




Java games rock!


« Reply #66 - Posted 2003-08-03 05:48:20 »

my application would work only like 1/3 of the time i ran it, but now i removed that texture.bind(gl) statement, and its working.... why is the texture being displayed if i dont bind it?
Offline epotash

Senior Newbie




Java games rock!


« Reply #67 - Posted 2003-08-03 05:52:50 »

those are some great results... where can i find the original application? did you post your code, i would like to try to run it...

wait, damn.  its still not working 100%, its soo wierd, its just like randomly choosing when to work.  and it seems that when it doesnt work once it will stop working until i like recompile or restart the terminal.  this is sooooo annoying
Offline kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #68 - Posted 2003-08-03 06:17:53 »

Could it be a driver problem? What GFX card are you running on and have you got the latest/best driver?

Kev

Offline Daath

Junior Duke




Java games rock!


« Reply #69 - Posted 2003-08-03 16:47:26 »

i tried to run it and got this:
net.java.games.jogl.GLException: Surface already unlocked
     at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.unlockSurface(WindowsOnscreenGLContext.java:189)
     at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.free(WindowsOnscreenGLContext.java:131)
     at net.java.games.jogl.impl.GLContext.invokeGL(GLContext.java:197)
     at net.java.games.jogl.GLCanvas.displayImpl(GLCanvas.java:179)
     at net.java.games.jogl.GLCanvas.display(GLCanvas.java:84)
     at net.java.games.jogl.Animator$1.run(Animator.java:104)
     at java.lang.Thread.run(Thread.java:534)
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #70 - Posted 2003-08-10 08:11:04 »

Quote
For completeness, Troggan has provided update versions of my loaders that fix the texture size bug (e.g. it now copes with wierd shape images) and also removed depedancy on my GameFrame code Smiley

He's posted them here:
<urls...>

I've only just needed textures (shock! horror!) so before I go and reinvent the wheel yet again I remembered this post. Are these the most up to date versions? It would be nice to have this or something similar as part of the Jogl package, it seems lots of people are using these Smiley

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #71 - Posted 2003-08-10 08:30:53 »

Yep, I think troggans versions are the latest still. Greg did say something about coming back to his versions but not heard anything for a while...

In Theory (tm) the texture loaders (the latest ones) should deal with all textures.

Kev

Offline troggan

Junior Duke




no guts no glory


« Reply #72 - Posted 2003-08-10 09:04:13 »

Yeah..putting that stuff into the jogl library would be a very good move.  Or at least putting it into the Wikki where everyone finds the latest version.

(http://www.wannawork.de) - Will work for food
(http://tvbrowser.org) - Java EPG
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #73 - Posted 2003-08-10 09:59:01 »

Well i gave those a try, and failed miserably Sad Seems I was getting NULL texture ids constantly. I hacked a quick conversion from one of my LWJGL texture classes and hit the same problem..

Seems to be an initialisation thing, if i delay the loading until the gl canvas has been displayed at least once it works fine.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline kevglass

JGO Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #74 - Posted 2003-08-10 10:03:39 »

I've not found that you needed display the canvas first, just that you have to wait until init() has been called on GLEventListener.

Kev

Offline gregorypierce

Senior Duke




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


« Reply #75 - Posted 2003-08-10 12:39:29 »

I'm back Smiley I'm working on the updated classes as we speak. I had been caught up with JInput OSX, but now that the input stuff is under control and is entering bug fix mode - I'm coming back to this before tackling Joal as it may be more than a simple recompile Cheesy

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 Jens

Senior Duke




Java for games!


« Reply #76 - Posted 2003-08-13 12:58:22 »

It would be nice to have the files available for download somewhere on the Jogl-Homepage, if that's possible.

Xith3D Getting Started Guide (PDF,HTML,Source)
Offline gregorypierce

Senior Duke




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


« Reply #77 - Posted 2003-08-13 14:29:03 »

I'll have to email the appropriate people about that. While I have permissions to upload those files, they aren't part of the official core.

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 Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #78 - Posted 2003-08-14 03:43:47 »

Gregory,

Have you taken a look at the changes myself and troggan made based on your original texture loader? (a download link is listed above)

The main part was to remove the switch statement for check the image type and just check an intermediate image of the type GL is expected and copy the source image into that? I was just wondering what you thought, can you see any problems, etc..

Cheers,

Kev

Offline gregorypierce

Senior Duke




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


« Reply #79 - Posted 2003-08-14 11:59:42 »

Yeah I took a look at what you guys had done and its good stuff. I had to do some things a little bit differently, but at its core its fundamentally the same approach as what you guys chose (remove the srcPixelFormat as an option for the user and derive it from the texture data). I spent some time putting in AnimatedTextures and QuicktimeTexture extends the AnimatedTexture stuff. All in all - happy happy stuff Smiley

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 Kernel


Medals: 186
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #80 - Posted 2003-08-14 12:01:35 »

Great, looking forward to see the results Smiley

Kev

Offline Java Cool Dude

Senior Duke




Java forever


« Reply #81 - Posted 2003-08-14 14:01:54 »

I have a question and I'm rather hesistant to put it here seeing my limited grasp of opengl and its internal mechanisms.
But anyways let me come out with it and bite on my fingers later.
Here's the deal: I'm writting my own texturing class that takes png, gif and jpg image and dumps em into arrays representing the ARGB channels.
Assuming that opengl takes bytes to create textures, I think it might be alright to modify my following code (used it to show displacement map in a 2D applet) so that it creates byte array instead of int and use em in the said process.
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  
import java.awt.*;                                      //Used for Image and Color's definitions
import java.awt.image.PixelGrabber;                     //Defines the pixelGrabber

class grabPixels                                        //This class will grab the texture's and heightmap's pixels
{
  int[]     r,g,b,                                      //Red, green and blue components of every pixel grabbed
            texels;                                     //This array will hold the pixels of the texture image

  point3f[] point;                                      //This array holds the image's pixels as 3D points

  public void initImage(displacement_map mc){           //Setting up the arrays' sizes and converting the pixels into 3D points

    int size   = mc.image_w*mc.image_h,                 //Size of the arrays
        R      = 0,
        G      = 0,
        B      = 0,                                     //Temporary red,green and blue components of a pixel
        pointer= 0;                                     //This will point out the current pixel we're working on

    mc.pixels  = new int[size];
    texels     = new int[size];
    g          = new int[size];
    b          = new int[size];
    r          = new int[size];

    mc.normal  = new vec3f[size];
    mc.z       = new float[size];
    point      = new point3f[size];



    getPixels(mc.map    ,mc.pixels,mc.image_w,mc.image_h);
    getPixels(mc.texture,texels   ,mc.image_w,mc.image_h);

    for(int a=0; a <mc.image_h; a++)
      for(int i=0; i <mc.image_w;  i++){

        R          = (mc.pixels[pointer] >> 16) & 0xFF;
        G          = (mc.pixels[pointer] >>  8) & 0xFF;
        B          =  mc.pixels[pointer]        & 0xFF;
        r[pointer] = (texels[pointer]    >> 16) & 0xFF;
        g[pointer] = (texels[pointer]    >>  8) & 0xFF;
        b[pointer] =  texels[pointer]           & 0xFF;

        point[pointer] = new point3f((float)i,
                                     (float)a,
                                     (mc.z[pointer] = (float)(R + G + B)/12f));
        pointer++;
      }

      mc.normal = new normals().assignNormals(point,mc.image_w,mc.image_h,true);
      System.gc();
  }

  public int[] getPixels(Image bumpThis,int[] getPixNum, int image_w, int image_h)
  {
    try{
      new PixelGrabber(bumpThis,0,0,image_w,image_h,getPixNum,0,image_w).grabPixels();
    }
    catch (InterruptedException e) {}
    System.out.println("Extracting picture's pixels");
    return getPixNum;
  }

}


Any comments on that one?
The code posted above is rather old and I don't feel like tweaking it any longer so please don't pay much attentions to the errors found in there.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #82 - Posted 2003-08-14 14:15:26 »

Quote

Here's the deal: I'm writting my own texturing class that takes png, gif and jpg image and dumps em into arrays representing the ARGB channels.
Any comments on that one?


Yes - don't bother Tongue save yourself some time and grab the files linked a couple of pages back. You'll have all the image support you listed up and working in minutes Cheesy

Unless you've got a really good reason you need your own version...?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Java Cool Dude

Senior Duke




Java forever


« Reply #83 - Posted 2003-08-14 14:22:51 »

Quote


Yes - don't bother Tongue save yourself some time and grab the files linked a couple of pages back. You'll have all the image support you listed up and working in minutes Cheesy

Unless you've got a really good reason you need your own version...?


Well I've been using the fine work written by Mr Greg up to now, but I feel like having something that's been coded from scratch all by myself Grin
Call it "re-inventing the wheel" but that's how things work out for me ;p.
Btw Greg, do you mind if I play around a bit with your code and add support to TGA images and potentially bmp?
Offline Java Cool Dude

Senior Duke




Java forever


« Reply #84 - Posted 2003-08-14 17:27:19 »

Got something very basic to work correctly
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  
class load_image
{
  java.awt.Image tex;
  byte[]         data;
  int            width,
                 height,
                 pixels[];

  load_image(){

    destroy();
  }

  void generate_texture_info(String texture_name, int type){

    try{
      tex = java.awt.Toolkit.getDefaultToolkit().getImage(texture_name);
    }
    catch(NullPointerException e){
      System.out.println(e);
    }

    while(width <= 0 || height <= 0){
      width      = tex.getWidth(null);
      height     = tex.getHeight(null);
    }

    pixels     = new int[width*height];
    extract_pixels();

    switch(type){
      case  net.java.games.jogl.GL.GL_RGB:

        data = new byte[pixels.length*3];
        for(int i = 0,a = 0; i<pixels.length; i++, a+= 3){
          data[a+0] = (byte)((pixels[i] >> 16) & 0xFF);
          data[a+1] = (byte)((pixels[i] >>  8) & 0xFF);
          data[a+2] = (byte) (pixels[i]        & 0xFF);
        }
      break;
      case net.java.games.jogl.GL.GL_RGBA:

        data = new byte[pixels.length*4];
        for(int i =0,a = 0; i<pixels.length; i++, a+= 4){
          data[a+3] = (byte)((pixels[i] >> 24) & 0xFF);
          data[a+0] = (byte)((pixels[i] >> 16) & 0xFF);
          data[a+1] = (byte)((pixels[i] >>  8) & 0xFF);
          data[a+2] = (byte)( pixels[i]        & 0xFF);
        }
      break;
      default: System.out.println("Unrecognized GL format or not supported yet ^_^");
    }
  }

  void destroy(){

    tex    = null;
    data   = null;
    width  = -1;
    height = -1;
    pixels = null;
  }

  void extract_pixels(){

    try{
      new java.awt.image.PixelGrabber(tex,0,0,width,height,pixels,0,width).grabPixels();
    }
    catch (InterruptedException e) {}
  }
}

Mr Greg I dunno why but when I load up jpg textures via your excellent loader, the color seems a bit brownish or indfidel to the origin.
However all those syndromes disappear at once when I deal with pngs.
Can you check that out please Smiley
Edit:
Here's a screenshot and a simple demo as well
http://www.realityflux.com/abba/loader.jpg
http://www.realityflux.com/abba/Simple%20Texture%20Loader.zip
Tested with gif, png and jpg Grin
Edit2: oops mixed up the alpha and red channels ...fixed Smiley
Offline gregorypierce

Senior Duke




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


« Reply #85 - Posted 2003-08-14 19:51:04 »

Don't worry about making cnanges to the code - we can all learn from whatever changes you make. Also don't worry about asking questions - even if they seem naive. For every question you don't ask, there are probaby 10 other people out there who have the exact same question who just haven't asked it.

Asking questions - even stupid ones, is how we learn. Its unfortunate that as we get older we start to get embarassed about asking questions. If you don't know the answer to a question - its not a stupid question  Grin

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 gregorypierce

Senior Duke




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


« Reply #86 - Posted 2003-08-14 19:52:55 »

I'll also take a look at your JPG issue (I never use them), but its likely because they aren't in the same texture format as what I load in. Most likely some of the channels of RGB are in a different order.

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 Java Cool Dude

Senior Duke




Java forever


« Reply #87 - Posted 2003-08-14 20:08:56 »

Thank you Sir, I appreciate your response Smiley.
Offline Java Cool Dude

Senior Duke




Java forever


« Reply #88 - Posted 2003-08-14 23:45:27 »

Ah the wonders of unregistred image processing-software, all good all good Grin
The label that shows up in the left corner of any image manipulated with "Image Converter and Editor" was an indicator that java acutally flips images up side down before rendering them to the screen...or that's what I think it does(maybe it's the way pixels are mapped in windows...shrugs).
I had to come up with a trick to reverse the effect.
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  
class load_image
{
  java.awt.Image tex;
  byte[]         data;
  int            width,
                 height,
                 pixels[];

  load_image(){

    destroy();
  }

  void generate_texture_info(String texture_name, int type){

    try{
      tex = java.awt.Toolkit.getDefaultToolkit().getImage(texture_name);
    }
    catch(NullPointerException e){
      System.out.println(e);
    }

    while(width <= 0 || height <= 0){
      width      = tex.getWidth(null);
      height     = tex.getHeight(null);
    }

    pixels     = new int[width*height];
    extract_pixels();

    int pointer =0;

    switch(type){
      case  net.java.games.jogl.GL.GL_RGB:

        data = new byte[pixels.length*3];
        for(int y = height -1; y>=0; y--)
        for(int x = 0; x<width; x++){
          data[pointer+0] = (byte)((pixels[y*width + x] >> 16) & 0xFF);
          data[pointer+1] = (byte)((pixels[y*width + x] >>  8) & 0xFF);
          data[pointer+2] = (byte) (pixels[y*width + x]        & 0xFF);
          pointer+=3;
        }
      break;
      case net.java.games.jogl.GL.GL_RGBA:

        data = new byte[pixels.length*4];
        for(int y = height -1; y>=0; y--)
        for(int x = 0; x<width; x++){
          data[pointer+3] = (byte)((pixels[y*width + x] >> 24) & 0xFF);
          data[pointer+0] = (byte)((pixels[y*width + x] >> 16) & 0xFF);
          data[pointer+1] = (byte)((pixels[y*width + x] >>  8) & 0xFF);
          data[pointer+2] = (byte)( pixels[y*width + x]        & 0xFF);
          pointer+=4;
        }
      break;
      default: System.out.println("Unrecognized GL mode or not supported yet ^_^");
    }
  }

  void destroy(){

    tex    = null;
    data   = null;
    width  = -1;
    height = -1;
    pixels = null;
  }

  void extract_pixels(){

    try{
      new java.awt.image.PixelGrabber(tex,0,0,width,height,pixels,0,width).grabPixels();
    }
    catch (InterruptedException e) {}
  }
}

Updated the package as well  Cheesy
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #89 - Posted 2003-08-17 14:20:17 »

Quote
Yeah I took a look at what you guys had done and its good stuff. I spent some time putting in AnimatedTextures and QuicktimeTexture extends the AnimatedTexture stuff. All in all - happy happy stuff Smiley


I noticed that the TextureLoader uses the actual resource name/filename as the key for the texture objects, I've found it better in the past to asign an abstract name to images thats independant of the filename.

The actual changes are minimal (add name string to Texture, change key in TextureLoader) but its quite handy. Especially for things like tilesets where you can switch the actual resources but keep the names the same.

If you're making changes you might want to bear it in mind, after all theres no reason that people can't get the old behaviour using the resource name for both Smiley

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Pages: 1 2 [3] 4
  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.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (39 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (35 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!