Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (416)
games submitted by our members
Games in WIP (306)
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  
  gl constants <-> string mappings  (Read 1372 times)
0 Members and 1 Guest are viewing this topic.
Offline anarchotron

Junior Member




...precious bodily fluids.


« Posted 2005-09-11 08:00:34 »

Does LWJGL have a mapping from gl constants to string representations of those constants?  E.g. I need to convert "GL_TEXTURE" to GL_TEXTURE and so on, and vice-versa.  I don't see anything like this but I thought I'd check.
Offline princec
« League of Dukes »

JGO Kernel


Medals: 197
Projects: 3


Eh? Who? What? ... Me?


« Reply #1 - Posted 2005-09-11 14:53:43 »

Nope, it's beyond the remit of LWJGL, but fortunately I have a thingy to do it for me in SPGL Smiley

Cas Smiley

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 463
Projects: 4


Hand over your head.


« Reply #2 - Posted 2005-09-11 15:13:00 »

Using reflection it's a piece of cake.

If you have to do it often, you can cache the results in a HashMap.



But you shouldn't do it often for obvious reasons... Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec
« League of Dukes »

JGO Kernel


Medals: 197
Projects: 3


Eh? Who? What? ... Me?


« Reply #3 - Posted 2005-09-11 16:52:23 »

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  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
   /** A map of constant names to values */   
   private static final HashMap glConstantsMap = new HashMap(513, 1.0f);
   
   static {
      loadGLConstants();
   }

   /**
    * Decode a gl string constant
    */

   public static int decode(String glstring) throws OpenGLException {
      Integer i = (Integer) glConstantsMap.get(glstring.toUpperCase());
      if (i == null)
         throw new OpenGLException(glstring+" is not a recognised GL constant");
      else
         return i.intValue();      
   }
   
   /**
    * Recode a gl constant back into a string
    */

   public static String recode(int code) {
      for (Iterator i = glConstantsMap.keySet().iterator(); i.hasNext(); ) {
         String s = (String) i.next();
         Integer n = (Integer) glConstantsMap.get(s);
         if (n.intValue() == code)
            return s;
      }
      throw new OpenGLException(code+" is not a known GL code");
   }
   private static void loadGLConstants(Class intf) {
      Field[] field = intf.getFields();
      for (int i = 0; i < field.length; i ++) {
         try {
            if (Modifier.isStatic(field[i].getModifiers()) && Modifier.isPublic(field[i].getModifiers()) && Modifier.isFinal(field[i].getModifiers()) && field[i].getType().equals(int.class))
               glConstantsMap.put(field[i].getName(), new Integer(field[i].getInt(null)));
         } catch (Exception e) {
         }
      }
   }

   /**
    * Reads all the constant enumerations from this class and stores them
    * so we can decode them from strings.
    * @see #decode()
    * @see #recode()
    */

   private static void loadGLConstants() {
      Class[] classes = new Class[] {
         GL11.class,
         GL12.class,
         GL13.class,
         GL14.class,
         GL15.class,
         ARBMultitexture.class,
         ARBTextureCubeMap.class,
         ARBDepthTexture.class,
         ARBFragmentProgram.class,
         ARBMatrixPalette.class,
         ARBMultisample.class,
         ARBPointParameters.class,
         ARBShadow.class,
         ARBShadowAmbient.class,
         ARBTextureBorderClamp.class,
         ARBTextureCompression.class,
         ARBTextureEnvCombine.class,
         ARBTextureEnvDot3.class,
         ARBTextureMirroredRepeat.class,
         ARBTransposeMatrix.class,
         ARBVertexBlend.class,
         ARBVertexBufferObject.class,
         ARBVertexProgram.class,
         ARBWindowPos.class,
         EXTDrawRangeElements.class,
         EXTAbgr.class,
         EXTBgra.class,
         EXTBlendFuncSeparate.class,
         EXTBlendSubtract.class,
         EXTCompiledVertexArray.class,
         EXTFogCoord.class,
         EXTMultiDrawArrays.class,
         EXTPackedPixels.class,
         EXTPointParameters.class,
         EXTRescaleNormal.class,
         EXTSecondaryColor.class,
         EXTSeparateSpecularColor.class,
         EXTSharedTexturePalette.class,
         EXTStencilTwoSide.class,
         EXTStencilWrap.class,
         EXTTextureCompressionS3TC.class,
         EXTTextureEnvCombine.class,
         EXTTextureEnvDot3.class,
         EXTTextureFilterAnisotropic.class,
         EXTTextureLODBias.class,
         EXTVertexShader.class,
         EXTVertexWeighting.class,
         ATIElementArray.class,
         ATIEnvmapBumpmap.class,
         ATIFragmentShader.class,
         ATIPnTriangles.class,
         ATISeparateStencil.class,
         ATITextureMirrorOnce.class,
         ATIVertexArrayObject.class,
         ATIVertexStreams.class,
         NVCopyDepthToColor.class,
         NVDepthClamp.class,
         NVEvaluators.class,
         NVFence.class,
         NVFogDistance.class,
         NVLightMaxExponent.class,
         NVOcclusionQuery.class,
         NVPackedDepthStencil.class,
         NVPointSprite.class,
         NVRegisterCombiners.class,
         NVRegisterCombiners2.class,
         NVTexgenReflection.class,
         NVTextureEnvCombine4.class,
         NVTextureRectangle.class,
         NVTextureShader.class,
         NVTextureShader2.class,
         NVTextureShader3.class,
         NVVertexArrayRange.class,
         NVVertexArrayRange2.class,
         NVVertexProgram.class
      };
      for (int i = 0; i < classes.length; i ++) {
         loadGLConstants(classes[i]);
      }
   }


Cas Smiley


Offline Riven
« League of Dukes »

JGO Overlord


Medals: 463
Projects: 4


Hand over your head.


« Reply #4 - Posted 2005-09-11 20:55:10 »

recode(..) would be much faster if it used a HashMap with the keys/values of the glConstantsMap flipped. Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline princec
« League of Dukes »

JGO Kernel


Medals: 197
Projects: 3


Eh? Who? What? ... Me?


« Reply #5 - Posted 2005-09-11 23:52:55 »

Well, it might be, except that I only use that method during development to read XML files in...

Cas Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
BrassApparatus (6 views)
2013-06-19 08:52:37

NegativeZero (11 views)
2013-06-19 03:31:52

NegativeZero (13 views)
2013-06-19 03:24:09

Jesse_Attard (18 views)
2013-06-18 22:03:02

HeroesGraveDev (59 views)
2013-06-15 23:35:23

Vermeer (59 views)
2013-06-14 20:08:06

davedes (58 views)
2013-06-14 16:03:55

alaslipknot (52 views)
2013-06-13 07:56:31

Roquen (73 views)
2013-06-12 04:12:32

alaslipknot (58 views)
2013-06-10 19:30:18
Smoothing Algorithm Question
by UprightPath
2013-05-28 02:58:26

Smoothing Algorithm Question
by UprightPath
2013-05-28 02:57:33

Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38
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!