use of org.lwjgl.opengl.GL11.GL_TRIANGLES in project Wizardry by TeamWizardry.
the class FairyData method render.
@SideOnly(Side.CLIENT)
public void render(World world, Vec3d pos, Vec3d prevPos, float partialTicks) {
if (!wasTamperedWith && !isDepressed) {
LibParticles.FAIRY_HEAD(world, pos.add(0, 0.25, 0), primaryColor);
ParticleBuilder glitter = new ParticleBuilder(age / 2);
glitter.setRender(new ResourceLocation(Wizardry.MODID, NBTConstants.MISC.SPARKLE_BLURRED));
glitter.setAlphaFunction(new InterpFloatInOut(0.2f, 1f));
if (RandUtil.nextInt(3) == 0)
ParticleSpawner.spawn(glitter, world, new StaticInterp<>(pos), 1, 0, (i, build) -> {
build.setMotion(new Vec3d(RandUtil.nextDouble(-0.01, 0.01), RandUtil.nextDouble(-0.01, 0.01), RandUtil.nextDouble(-0.01, 0.01)));
if (RandUtil.nextBoolean())
build.setColor(primaryColor);
else
build.setColor(secondaryColor);
if (isDepressed) {
build.setCollision(true);
build.enableMotionCalculation();
build.setAcceleration(new Vec3d(0, -0.005, 0));
}
});
} else {
{
GlStateManager.pushMatrix();
EntityPlayer player = Minecraft.getMinecraft().player;
if (player == null)
return;
double interpPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
double interpPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
double interpPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
GlStateManager.translate(-interpPosX, -interpPosY, -interpPosZ);
GlStateManager.translate(pos.x, pos.y, pos.z);
Minecraft.getMinecraft().entityRenderer.disableLightmap();
GlStateManager.enableDepth();
GlStateManager.disableCull();
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE);
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.color(1, 1, 1, 1);
GlStateManager.disableTexture2D();
GlStateManager.enableColorMaterial();
GlStateManager.disableLighting();
GlStateManager.shadeModel(GL11.GL_SMOOTH);
int alphaFunc = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC);
float alphaTest = GL11.glGetFloat(GL11.GL_ALPHA_TEST_REF);
GlStateManager.alphaFunc(GL11.GL_ALWAYS, 1);
GlStateManager.pushMatrix();
GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate((float) (Minecraft.getMinecraft().getRenderManager().options.thirdPersonView == 2 ? -1 : 1) * Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder bb = tessellator.getBuffer();
double radius = 0.1;
Color color = primaryColor;
bb.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR);
for (int i = 0; i <= 50; i++) {
double x = radius * MathHelper.cos((float) ((i / 50.0) * Math.PI * 2));
double z = radius * MathHelper.sin((float) ((i / 50.0) * Math.PI * 2));
bb.pos(x, z, 0).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
}
tessellator.draw();
GlStateManager.popMatrix();
bb.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION_COLOR);
Vec3d sub = pos.subtract(prevPos).scale(-1).add(0, 0.2, 0).scale(3);
Vec3d posCross = sub.crossProduct(new Vec3d(0, 1, 0)).normalize();
Vec3d posPerp = posCross.crossProduct(sub).normalize().scale(radius - 0.2);
Vec3d vec1 = posPerp;
Vec3d vec2 = posPerp.scale(-1);
bb.pos(sub.x, sub.y, sub.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
bb.pos(vec1.x, vec1.y, vec1.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
bb.pos(vec2.x, vec2.y, vec2.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
Vec3d vec3 = posCross.scale(radius);
Vec3d vec4 = posCross.scale(-1).scale(radius);
bb.pos(sub.x, sub.y, sub.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
bb.pos(vec3.x, vec3.y, vec3.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
bb.pos(vec4.x, vec4.y, vec4.z).color(color.getRed(), color.getGreen(), color.getBlue(), 255).endVertex();
tessellator.draw();
GlStateManager.pushMatrix();
GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate((float) (Minecraft.getMinecraft().getRenderManager().options.thirdPersonView == 2 ? -1 : 1) * Minecraft.getMinecraft().getRenderManager().playerViewX, 1.0F, 0.0F, 0.0F);
int sections = 50;
float epsilon = 2 * (float) Math.PI / sections;
double innerRadius = radius;
double outerRadius = radius + 0.01;
Color inner = primaryColor;
Color outer = new Color(primaryColor.getRed(), primaryColor.getGreen(), primaryColor.getBlue(), 0);
bb.begin(GL11.GL_TRIANGLE_STRIP, DefaultVertexFormats.POSITION_COLOR);
for (int i = 0; i <= sections; i++) {
float angle = i * epsilon;
float nextAngle = (i + 1) * epsilon;
float x1 = (float) (MathHelper.cos(angle) * innerRadius);
float y1 = (float) (MathHelper.sin(angle) * innerRadius);
float x2 = (float) (MathHelper.cos(nextAngle) * outerRadius);
float y2 = (float) (MathHelper.sin(nextAngle) * outerRadius);
bb.pos(x1, y1, 0).color(inner.getRed(), inner.getGreen(), inner.getBlue(), inner.getAlpha()).endVertex();
bb.pos(x2, y2, 0).color(outer.getRed(), outer.getGreen(), outer.getBlue(), outer.getAlpha()).endVertex();
}
tessellator.draw();
radius = 0.2;
color = secondaryColor;
GlStateManager.translate(0, 0, 0.01);
bb.begin(GL11.GL_TRIANGLE_FAN, DefaultVertexFormats.POSITION_COLOR);
bb.pos(0, 0, 0).color(color.getRed(), color.getGreen(), color.getBlue(), 100).endVertex();
for (int i = 0; i <= 50; i++) {
double x = radius * MathHelper.cos((float) ((i / 50.0) * Math.PI * 2));
double z = radius * MathHelper.sin((float) ((i / 50.0) * Math.PI * 2));
bb.pos(x, z, 0).color(color.getRed(), color.getGreen(), color.getBlue(), 0).endVertex();
}
tessellator.draw();
GlStateManager.translate(0, 0, -0.01);
GlStateManager.alphaFunc(alphaFunc, alphaTest);
GlStateManager.disableBlend();
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
GlStateManager.disableColorMaterial();
Minecraft.getMinecraft().entityRenderer.enableLightmap();
GlStateManager.enableDepth();
GlStateManager.popMatrix();
GlStateManager.popMatrix();
}
}
}
use of org.lwjgl.opengl.GL11.GL_TRIANGLES in project chunkstories by Hugobros3.
the class GLFWGameWindow method displaySplashScreen.
@SuppressWarnings("unused")
private void displaySplashScreen() throws IOException {
int texture = glGenTextures();
InputStream is = getClass().getResourceAsStream("/splash.png");
PNGDecoder decoder = new PNGDecoder(is);
int width = decoder.getWidth();
int height = decoder.getHeight();
ByteBuffer temp = ByteBuffer.allocateDirect(4 * width * height);
decoder.decode(temp, width * 4, Format.RGBA);
is.close();
// ChunkStoriesLogger.getInstance().log("decoded " + width + " by " + height + " pixels (" + name + ")", ChunkStoriesLogger.LogType.RENDERING, ChunkStoriesLogger.LogLevel.DEBUG);
temp.flip();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer) temp);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
int shaderProgramId = glCreateProgram();
int vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
int fragShaderId = glCreateShader(GL_FRAGMENT_SHADER);
String vertexSource = "#version 330\n\n\nin vec3 vertexIn;\nout vec2 texCoord;\nuniform float ratio;\n\nvoid main()\n{\ngl_Position = vec4(vertexIn.x*ratio, vertexIn.y, 0.0, 1.0);\ntexCoord = vertexIn.xy*0.5+0.5;\n}";
String fragSource = "#version 330\nuniform sampler2D diffuseTexture;\n\nin vec2 texCoord;\nout vec4 fragColor;\n\nvoid main()\n{\nfragColor = texture(diffuseTexture, vec2(texCoord.x, 1.0-texCoord.y));\n}\n";
// System.out.println(vertexSource);
// System.out.println(fragSource);
glShaderSource(vertexShaderId, vertexSource);
glCompileShader(vertexShaderId);
glBindFragDataLocation(shaderProgramId, 0, "fragColor");
glShaderSource(fragShaderId, fragSource);
glCompileShader(fragShaderId);
glAttachShader(shaderProgramId, vertexShaderId);
glAttachShader(shaderProgramId, fragShaderId);
glLinkProgram(shaderProgramId);
glUseProgram(shaderProgramId);
int uniformLocation = glGetUniformLocation(shaderProgramId, "diffuseTexture");
// glUniform2f(uniformLocation, ((Vector2fc)uniformData).x(), ((Vector2fc)uniformData).y());
glUniform1i(uniformLocation, (Integer) 0);
float ratio = (float) windowHeight / windowWidth;
uniformLocation = glGetUniformLocation(shaderProgramId, "ratio");
glUniform1f(uniformLocation, ratio);
glValidateProgram(shaderProgramId);
FloatBuffer fsQuadBuffer = BufferUtils.createFloatBuffer(6 * 2);
fsQuadBuffer.put(new float[] { 1f, 1f, -1f, -1f, 1f, -1f, 1f, 1f, -1f, 1f, -1f, -1f });
fsQuadBuffer.flip();
int vertexBuffer = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, (FloatBuffer) fsQuadBuffer, GL_STATIC_DRAW);
int location = glGetAttribLocation(shaderProgramId, "vertexIn");
glEnableVertexAttribArray(location);
glVertexAttribPointer(location, 2, GL_FLOAT, false, 0, 0L);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// while(1 - Math.floor(1) == 0 && !glfwWindowShouldClose(glfwWindowHandle))
{
glClearColor(0.25f, 0.25f, 0.25f, 1f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Draw happens here
glDrawArrays(GL_TRIANGLES, 0, 6);
glfwSwapBuffers(glfwWindowHandle);
glfwPollEvents();
}
glDisable(GL_BLEND);
glDisableVertexAttribArray(location);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glDeleteBuffers(vertexBuffer);
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteTextures(texture);
glUseProgram(0);
glDeleteProgram(shaderProgramId);
glDeleteShader(vertexShaderId);
glDeleteShader(fragShaderId);
glClearColor(0.0f, 0.0f, 0.0f, 1f);
}
use of org.lwjgl.opengl.GL11.GL_TRIANGLES in project ImmersivePortalsMod by qouteall.
the class ViewAreaRenderer method buildPortalViewAreaTrianglesBuffer.
private static void buildPortalViewAreaTrianglesBuffer(Vec3d fogColor, Portal portal, BufferBuilder bufferbuilder, Vec3d cameraPos, float partialTicks, float layerWidth) {
// if layerWidth is small, the teleportation will not be seamless
// counter-clockwise triangles are front-faced in default
bufferbuilder.begin(GL_TRIANGLES, VertexFormats.POSITION_COLOR);
Vec3d posInPlayerCoordinate = portal.getPos().subtract(cameraPos);
if (portal instanceof Mirror) {
posInPlayerCoordinate = posInPlayerCoordinate.add(portal.getNormal().multiply(-0.001));
}
Consumer<Vec3d> vertexOutput = p -> putIntoVertex(bufferbuilder, p, fogColor);
if (portal.specialShape == null) {
generateTriangleRectangular(vertexOutput, portal, layerWidth, posInPlayerCoordinate);
} else {
generateTriangleSpecial(vertexOutput, portal, layerWidth, posInPlayerCoordinate);
}
if (shouldRenderAdditionalBox(portal, cameraPos)) {
renderAdditionalBox(portal, cameraPos, vertexOutput);
}
}
Aggregations