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 (590)
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  
  Loading and Drawing 2d Images with drawPixels in JOGL  (Read 2404 times)
0 Members and 1 Guest are viewing this topic.
Offline Epo

Senior Newbie


Projects: 1


Green Tea and swords


« Posted 2009-05-11 13:04:26 »



This class will load transparent or non-transparent images into some buffer with there width and height
The transparent color will the pixel color at the lower left of the image.
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  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.awt.Color;
import javax.imageio.ImageIO;

public class StaticImages {

   public static ByteBuffer _32BITImages[] = new ByteBuffer[32];
   public static int       _Width[]= new int[32];
   public static int       _Height[]= new int[32];
   
   
   
   
   public static void setBTrans(BufferedImage name,int temp){
      for (int _yi = 0; _yi<name.getHeight();_yi++){
      for (int _xi = 0; _xi<name.getWidth();_xi++){
      if (name.getRGB(_xi,_yi)==temp)
      name.setRGB(_xi,_yi,0);
      }//END X FOR STATEMENT
      }//END Y FOR STATEMENT
     
      }//END METHOD
   
   
   
   
   
   
   
   
   
   private static int fixRGB(int num){
      int Alpha = 0xFF000000;
      int Red   = 0x00FF0000;
      int Green = 0x0000FF00;
      int Blue  = 0x000000FF;
      int finalR = 0;
     
      Red   =   num & Red;
      Red   =   Red << 8;
     
      Green   =   num & Green;
      Green   =   Green << 8;
     
      Blue   =   num & Blue;
      Blue   =   Blue << 8;
     
      Alpha  =   num & Alpha;
      Alpha  =   Alpha >>> 24;
     
     
      finalR = Red | Green | Blue | Alpha;
     
      return finalR;
   }//END METHOD
   
   
   
   

   public static void Load32BitImg(String name,int id,java.awt.GraphicsDevice GD,boolean trans){
      try{

      Image imgTemp;
      imgTemp = (Image)ImageIO.read(new File(name));
      ByteBuffer buf;
      //System.out.println("Found File");
     
      BufferedImage Bimg = GD.getDefaultConfiguration().createCompatibleImage(imgTemp.getWidth(null),imgTemp.getHeight(null),Color.BITMASK);
      Bimg.getGraphics().drawImage(imgTemp,0,0,null);
     
      if (trans)
      setBTrans(Bimg,Bimg.getRGB(0,Bimg.getHeight()-1));
     
      buf = ByteBuffer.allocateDirect((Bimg.getWidth()*Bimg.getHeight())*4);
     
      for (int y = 0; y< Bimg.getHeight();y++){
         for (int x = 0; x< Bimg.getWidth();x++)
      buf.putInt(fixRGB(Bimg.getRGB(x, Bimg.getHeight()-y-1)));
      }//END FOR LOOP
         
      //System.out.println("BUFFER MADE");
     
      _32BITImages[id] = buf;
      _Width[id] = Bimg.getWidth();
      _Height[id] = Bimg.getHeight();
     
      }catch(IOException ie){
      System.out.println("Error Reading Image");
      }//END TRY AND CATCH STATEMENT
      }//END METHOD
   
   
   
   
}//END CLASS




How to draw those images.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
       tempGL.glEnable(GL.GL_BLEND);
       StaticImages._32BITImages[imgID].clear();
     
   tempGL.glRasterPos2i(X Position,Y Position);
   tempGL.glDrawPixels(StaticImages._Width[imgID],
                     StaticImages._Height[imgID],
                     GL.GL_RGBA,
                     GL.GL_UNSIGNED_INT_8_8_8_8_REV,
                     StaticImages._32BITImages[imgID]);
        tempGL.glDisable(GL.GL_BLEND);

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.

trollwarrior1 (30 views)
2014-11-22 12:13:56

xFryIx (72 views)
2014-11-13 12:34:49

digdugdiggy (51 views)
2014-11-12 21:11:50

digdugdiggy (45 views)
2014-11-12 21:10:15

digdugdiggy (39 views)
2014-11-12 21:09:33

kovacsa (63 views)
2014-11-07 19:57:14

TehJavaDev (68 views)
2014-11-03 22:04:50

BurntPizza (66 views)
2014-11-03 18:54:52

moogie (81 views)
2014-11-03 06:22:04

CopyableCougar4 (81 views)
2014-11-01 23:36:41
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!