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
130
131
132
133
134
|
#include "stdafx.h"
#include "..\Minecraft.World\Random.h"
#include "..\Minecraft.World\net.minecraft.world.level.tile.entity.h"
#include "Tesselator.h"
#include "TileEntityRenderDispatcher.h"
#include "Camera.h"
#include "..\Minecraft.World\FloatBuffer.h"
#include "TheEndPortalRenderer.h"
ResourceLocation TheEndPortalRenderer::END_SKY_LOCATION = ResourceLocation(TN_MISC_TUNNEL);
ResourceLocation TheEndPortalRenderer::END_PORTAL_LOCATION = ResourceLocation(TN_MISC_PARTICLEFIELD);
int TheEndPortalRenderer::RANDOM_SEED = 31100;
Random TheEndPortalRenderer::RANDOM = Random(RANDOM_SEED);
void TheEndPortalRenderer::render(shared_ptr<TileEntity> _table, double x, double y, double z, float a, bool setColor, float alpha, bool useCompiled)
{
// 4J Convert as we aren't using a templated class
shared_ptr<TheEndPortalTileEntity> table = dynamic_pointer_cast<TheEndPortalTileEntity>(_table);
float xx = static_cast<float>(tileEntityRenderDispatcher->xPlayer);
float yy = static_cast<float>(tileEntityRenderDispatcher->yPlayer);
float zz = static_cast<float>(tileEntityRenderDispatcher->zPlayer);
glDisable(GL_LIGHTING);
RANDOM.setSeed(RANDOM_SEED);
float hoff = 12 / 16.0f;
for (int i = 0; i < 16; i++)
{
glPushMatrix();
float dist = (16 - (i));
float sscale = 1 / 16.0f;
float br = 1.0f / (dist + 1);
if (i == 0)
{
this->bindTexture(&END_SKY_LOCATION);
br = 0.1f;
dist = 65;
sscale = 1 / 8.0f;
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
if (i == 1)
{
this->bindTexture(&END_PORTAL_LOCATION);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE);
sscale = 1 / 2.0f;
}
float dd = static_cast<float>(-(y + hoff));
{
float ss1 = (float) (dd + Camera::yPlayerOffs);
float ss2 = (float) (dd + dist + Camera::yPlayerOffs);
float s = ss1 / ss2;
s = static_cast<float>(y + hoff) + s;
glTranslatef(xx, s, zz);
}
// 4J - note that the glTexGeni/glEnable calls don't actually do anything in our opengl wrapper version, everything is currently just inferred from the glTexGen calls.
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGen(GL_S, GL_OBJECT_PLANE, getBuffer(1, 0, 0, 0));
glTexGen(GL_T, GL_OBJECT_PLANE, getBuffer(0, 0, 1, 0));
glTexGen(GL_R, GL_OBJECT_PLANE, getBuffer(0, 0, 0, 1));
glTexGen(GL_Q, GL_EYE_PLANE, getBuffer(0, 1, 0, 0));
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
glPopMatrix();
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glTranslatef(0, System::currentTimeMillis() % 700000 / 700000.0f, 0);
glScalef(sscale, sscale, sscale);
glTranslatef(0.5f, 0.5f, 0);
glRotatef((i * i * 4321 + i * 9) * 2.0f, 0, 0, 1);
glTranslatef(-0.5f, -0.5f, 0);
glTranslatef(-xx, -zz, -yy);
float ss1 = (float) (dd + Camera::yPlayerOffs);
glTranslatef(Camera::xPlayerOffs * dist / ss1, Camera::zPlayerOffs * dist / ss1, -yy);
Tesselator *t = Tesselator::getInstance();
t->useProjectedTexture(true); // 4J added - turns on both the generation of texture coordinates in the vertex shader & perspective divide of the texture coord in the pixel shader
t->begin();
float r = RANDOM.nextFloat() * 0.5f + 0.1f;
float g = RANDOM.nextFloat() * 0.5f + 0.4f;
float b = RANDOM.nextFloat() * 0.5f + 0.5f;
if (i == 0) r = g = b = 1;
t->color(r * br, g * br, b * br, 1.0f);
t->vertex(x, y + hoff, z);
t->vertex(x, y + hoff, z + 1);
t->vertex(x + 1, y + hoff, z + 1);
t->vertex(x + 1, y + hoff, z);
t->end();
t->useProjectedTexture(false); // 4J added
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);
glEnable(GL_LIGHTING);
}
TheEndPortalRenderer::TheEndPortalRenderer()
{
lb = MemoryTracker::createFloatBuffer(16);
}
FloatBuffer *TheEndPortalRenderer::getBuffer(float a, float b, float c, float d)
{
lb->clear();
lb->put(a)->put(b)->put(c)->put(d);
lb->flip();
return lb;
}
|