Romejanic
Romejanic

Reputation: 427

Errors with shininess

I am working on a Minecraft mod, and I am attempting to make a gun gold when a specific person is logged on. I have everything worked out, except for the shininess itself. I used the code from this site to get the Ambient, Specular, Diffuse and Shininess of Gold, but when I run the game, I get this error:

GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_AMBIENT, 0.24725f);
GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_DIFFUSE, 0.75164f);
GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SPECULAR, 0.628281f);
GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 0.4f);

I copied the code from the site, but I did not feel like using a shader, so I tried writing it out as OpenGL code (as you can see above). However, when the gun renders, it colours gold (because I write the color code), but it does not shine, and this error is printed into the console:

2014-06-21 18:27:36 [SEVERE] [Minecraft-Client] ########## GL ERROR ##########
2014-06-21 18:27:36 [SEVERE] [Minecraft-Client] @ Post render
2014-06-21 18:27:36 [SEVERE] [Minecraft-Client] 1280: Invalid enum

Does anyone have any ideas? This obviously isn't a question about Minecraft modding, but more about the OpenGL rendering.

(btw, it is rendering with LWJGL and Java 6)

Upvotes: 0

Views: 151

Answers (1)

derhass
derhass

Reputation: 45352

The error occurs because GL_AMBIENT, GL_DIFFUSE and GL_SPECULAR are not valid arguments for glMaterialf(). Those define RGBA vectors of material coefficients, not just a single scalar value like you try set. You have to use glMaterialfv() instead and specify 4 components per parameter. The table you linked already maks this very clear by having 3 values (RGB) per parameter, they just ignor the alpha component, which isn't really relevent for the material itself, but you still have to specify one.

But I also have to warn you that the result will still not look too realistic unless some reflection technics are used, like environment mapping.

Upvotes: 2

Related Questions