Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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 1570 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

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


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

Online Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


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


Online Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


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
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


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.

 

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

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!