batch 2.1; entity lightfix

This commit is contained in:
JuiceyDev 2026-03-27 09:12:07 +01:00 committed by Tropical
parent 09e8a8f981
commit e71ff8699a
2 changed files with 43 additions and 15 deletions

View file

@ -358,16 +358,22 @@ void ItemRenderer::renderGuiItem(Font* font, Textures* textures,
Tile* tile = Tile::tiles[itemId];
glPushMatrix();
// 4J - original code left here for reference
// 4jcraft: original code reused for proper lighting
// force normalize
glEnable(GL_NORMALIZE);
glDisable(GL_RESCALE_NORMAL);
#if 1
glTranslatef((float)(x), (float)(y), 0.0f);
glScalef(fScaleX, fScaleY, 1.0f);
glTranslatef(-2.0f,3.0f, -3.0f + blitOffset);
glScalef(10.0f, 10.0f, 10.0f);
// does it work? too lazy to find out
glTranslatef((float)(x), (float)(y), 0.0f);
glScalef(fScaleX, fScaleY, 1.0f);
glTranslatef(-2.0f, 3.0f, -3.0f + blitOffset);
glScalef(10.0f, 10.0f, 10.0f);
glTranslatef(1.0f, 0.5f, 8.0f);
glScalef(1.0f, 1.0f, -1.0f);
glRotatef(180.0f + 30.0f, 1.0f, 0.0f, 0.0f);
glScalef(1.0f, -1.0f, 1.0f);
glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
#else
glTranslatef(x, y, 0.0f); // Translate to screen coords
@ -385,12 +391,16 @@ void ItemRenderer::renderGuiItem(Font* font, Textures* textures,
glRotatef(45.0f, 0.0f, 1.0f,
0.0f); // Rotate round y axis (centre at origin)
#endif
// 4J-PB - pass the alpha value in - the grass block
// render has the top surface coloured differently to
// the rest of the block
glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);
// 4J-PB - pass the alpha value in - the grass block
// render has the top surface coloured differently to
// the rest of the block
glRotatef(-90.0f, 0.0f, 1.0f, 0.0f);
// glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
tileRenderer->renderTile(tile, itemAuxValue, 1, fAlpha, useCompiled);
// glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
glDisable(GL_NORMALIZE);
glPopMatrix();
PIXEndNamedEvent();
} else if (Item::items[itemId]->hasMultipleSpriteLayers()) {

View file

@ -52,9 +52,27 @@ FloatBuffer* Lighting::getBuffer(float a, float b, float c, float d) {
}
void Lighting::turnOnGui() {
glPushMatrix();
glRotatef(-30, 0, 1, 0);
glRotatef(165, 1, 0, 0);
turnOn();
glPopMatrix();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
float a = 0.4f;
float d = 0.6f;
float s = 0.0f;
// big john machine
// (copied from turnon)
RenderManager.StateSetLightDirection(0, 0.129f, 0.965f, 0.224f);
glLight(GL_LIGHT0, GL_DIFFUSE, getBuffer(d, d, d, 1));
glLight(GL_LIGHT0, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
glLight(GL_LIGHT0, GL_SPECULAR, getBuffer(s, s, s, 1.0f));
RenderManager.StateSetLightDirection(1, -0.129f, 0.965f, -0.224f);
glLight(GL_LIGHT1, GL_DIFFUSE, getBuffer(d, d, d, 1));
glLight(GL_LIGHT1, GL_AMBIENT, getBuffer(0.0f, 0.0f, 0.0f, 1.0f));
glLight(GL_LIGHT1, GL_SPECULAR, getBuffer(s, s, s, 1.0f));
glShadeModel(GL_FLAT);
glLightModel(GL_LIGHT_MODEL_AMBIENT, getBuffer(a, a, a, 1));
}