aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/TheEndPortalRenderer.cpp
blob: 7837a4fa6fc39cd12a492b46065266f9ebada420 (plain)
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
#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"

void TheEndPortalRenderer::render(std::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
	std::shared_ptr<TheEndPortalTileEntity> table = dynamic_pointer_cast<TheEndPortalTileEntity>(_table);
	float xx = (float) (tileEntityRenderDispatcher->xPlayer);
	float yy = (float) (tileEntityRenderDispatcher->yPlayer);
	float zz = (float) (tileEntityRenderDispatcher->zPlayer);

	glDisable(GL_LIGHTING);

	Random random(31100);

	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(TN_MISC_TUNNEL); // 4J was "/misc/tunnel.png"
			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(TN_MISC_PARTICLEFIELD); // 4J was "/misc/particlefield.png"
			glEnable(GL_BLEND);
			glBlendFunc(GL_ONE, GL_ONE);
			sscale = 1 / 2.0f;
		}

		float dd = (float) -(y + hoff);
		{
			float ss1 = (float) (dd + Camera::yPlayerOffs);
			float ss2 = (float) (dd + dist + Camera::yPlayerOffs);
			float s = ss1 / ss2;
			s = (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;
}