use of org.lwjgl.opengl.GL11.glViewport 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.glViewport in project chunkstories by Hugobros3.
the class GLFWGameWindow method switchResolution.
private void switchResolution() {
long mainMonitor = glfwGetPrimaryMonitor();
GLFWVidMode currentVideoMode = glfwGetVideoMode(mainMonitor);
boolean isFullscreenEnabled = client.getConfiguration() == null ? false : client.getConfiguration().getBooleanOption("client.video.fullScreen");
if (isFullscreenEnabled) {
// Enable fullscreen using desktop resolution, by default on the primary monitor and at it's nominal video mode
String modeString = client.getConfiguration().getStringOption("client.video.fullScreenResolution");
if (modeString == null || modeString.contains("x") || !modeString.contains(":")) {
modeString = "1:" + currentVideoMode.width() + ":" + currentVideoMode.height() + ":" + currentVideoMode.refreshRate();
client.getConfiguration().getOption("client.video.fullScreenResolution").trySetting(modeString);
}
DisplayMode videoMode = findMatchForVideoMode(modeString);
glfwSetWindowMonitor(this.glfwWindowHandle, monitors[videoMode.monitorId - 1], 0, 0, videoMode.videoMode.width(), videoMode.videoMode.height(), videoMode.videoMode.refreshRate());
windowWidth = videoMode.videoMode.width();
windowHeight = videoMode.videoMode.height();
glViewport(0, 0, windowWidth, windowHeight);
if (layer != null)
layer.onResize(windowWidth, windowHeight);
} else {
glfwSetWindowMonitor(this.glfwWindowHandle, MemoryUtil.NULL, (currentVideoMode.width() - defaultWidth) / 2, (currentVideoMode.height() - defaultHeight) / 2, defaultWidth, defaultHeight, GLFW_DONT_CARE);
windowWidth = defaultWidth;
windowHeight = defaultHeight;
glViewport(0, 0, windowWidth, windowHeight);
if (layer != null)
layer.onResize(windowWidth, windowHeight);
}
}
use of org.lwjgl.opengl.GL11.glViewport in project Nothirium by Meldexun.
the class RenderChunkTaskCompile method run.
@Override
public RenderChunkTaskResult run() {
if (this.canceled()) {
return RenderChunkTaskResult.CANCELLED;
}
RegionRenderCacheBuilder bufferBuilderPack;
try {
bufferBuilderPack = BUFFER_QUEUE.take();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return RenderChunkTaskResult.CANCELLED;
}
if (this.canceled()) {
freeBuffer(bufferBuilderPack);
return RenderChunkTaskResult.CANCELLED;
}
try {
Minecraft mc = Minecraft.getMinecraft();
MutableBlockPos pos = new MutableBlockPos();
VisibilityGraph visibilityGraph = new VisibilityGraph();
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
pos.setPos(this.renderChunk.getX() + x, this.renderChunk.getY() + y, this.renderChunk.getZ() + z);
IBlockState blockState = this.chunkCache.getBlockState(pos);
if (blockState.getRenderType() == EnumBlockRenderType.INVISIBLE) {
continue;
}
for (Direction dir : Direction.ALL) {
if (blockState.doesSideBlockRendering(chunkCache, pos, EnumFacingUtil.getFacing(dir)))
visibilityGraph.setOpaque(pos.getX(), pos.getY(), pos.getZ(), dir);
}
// I will just quote another mod here "This is a ridiculously hacky workaround, I would not recommend it to anyone."
blockState.getBlock().hasTileEntity(blockState);
for (BlockRenderLayer layer : BlockRenderLayerUtil.ALL) {
if (Nothirium.isBetterFoliageInstalled ? !BetterFoliage.canRenderBlockInLayer(blockState.getBlock(), blockState, layer) : !blockState.getBlock().canRenderInLayer(blockState, layer)) {
continue;
}
ForgeHooksClient.setRenderLayer(layer);
BufferBuilder bufferBuilder = bufferBuilderPack.getWorldRendererByLayer(layer);
if (!bufferBuilder.isDrawing) {
bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
bufferBuilder.setTranslation(-this.renderChunk.getX(), -this.renderChunk.getY(), -this.renderChunk.getZ());
}
if (Nothirium.isBetterFoliageInstalled) {
BetterFoliage.renderWorldBlock(mc.getBlockRendererDispatcher(), blockState, pos, this.chunkCache, bufferBuilder, layer);
} else {
mc.getBlockRendererDispatcher().renderBlock(blockState, pos, this.chunkCache, bufferBuilder);
}
ForgeHooksClient.setRenderLayer(null);
}
}
}
if (this.canceled()) {
freeBuffer(bufferBuilderPack);
return RenderChunkTaskResult.CANCELLED;
}
}
VisibilitySet visibilitySet = visibilityGraph.compute();
if (bufferBuilderPack.getWorldRendererByLayer(BlockRenderLayer.TRANSLUCENT).isDrawing) {
BufferBuilder bufferBuilder = bufferBuilderPack.getWorldRendererByLayer(BlockRenderLayer.TRANSLUCENT);
Entity entity = mc.getRenderViewEntity();
double x = entity.posX - renderChunk.getX();
double y = (entity.posY + entity.getEyeHeight()) - renderChunk.getY();
double z = entity.posZ - renderChunk.getZ();
// use translation to fix float inaccuracy
bufferBuilder.setTranslation(x, y, z);
bufferBuilder.sortVertexData(0.0F, 0.0F, 0.0F);
}
if (this.canceled()) {
freeBuffer(bufferBuilderPack);
return RenderChunkTaskResult.CANCELLED;
}
BufferBuilder[] finishedBufferBuilders = Arrays.stream(BlockRenderLayerUtil.ALL).map(bufferBuilderPack::getWorldRendererByLayer).map(bufferBuilder -> {
if (!bufferBuilder.isDrawing) {
return null;
}
bufferBuilder.finishDrawing();
if (bufferBuilder.getVertexCount() == 0) {
return null;
}
return bufferBuilder;
}).toArray(BufferBuilder[]::new);
if (this.canceled()) {
freeBuffer(bufferBuilderPack);
return RenderChunkTaskResult.CANCELLED;
}
this.taskDispatcher.runOnRenderThread(() -> {
try {
if (!this.canceled()) {
this.renderChunk.setVisibility(visibilitySet);
for (ChunkRenderPass pass : ChunkRenderPass.ALL) {
BufferBuilder bufferBuilder = finishedBufferBuilders[pass.ordinal()];
if (bufferBuilder == null) {
this.renderChunk.setVBOPart(pass, null);
} else {
this.renderChunk.setVBOPart(pass, this.chunkRenderer.buffer(pass, bufferBuilder.getByteBuffer()));
}
}
}
} finally {
freeBuffer(bufferBuilderPack);
}
});
return RenderChunkTaskResult.SUCCESSFUL;
} catch (Throwable e) {
freeBuffer(bufferBuilderPack);
throw e;
}
}
use of org.lwjgl.opengl.GL11.glViewport in project Terasology by MovingBlocks.
the class GLFWSplashScreen method run.
@Override
public void run() {
if (!GLFW.glfwInit()) {
throw new RuntimeException("Cannot init GLFW!");
}
int width = 800;
int height = 289;
window = new Window(width, height, "", false);
pixel = new Texture();
ByteBuffer bytes = BufferUtils.createByteBuffer(4);
bytes.put((byte) -1).put((byte) -1).put((byte) -1).put((byte) -1);
bytes.flip();
pixel.bind();
pixel.uploadData(1, 1, bytes);
try {
widgets.add(new Image(GLFWSplashScreen.class.getResource("/splash/splash.png"), 0, 0));
widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_1.png"), 0, 0, TerasologyEngineStatus.PREPARING_SUBSYSTEMS.getDescription()));
widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_2.png"), 150, 0, TerasologyEngineStatus.INITIALIZING_MODULE_MANAGER.getDescription()));
widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_3.png"), 300, 0, TerasologyEngineStatus.INITIALIZING_ASSET_TYPES.getDescription()));
widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_4.png"), 450, 0, TerasologyEngineStatus.INITIALIZING_SUBSYSTEMS.getDescription()));
widgets.add(new ActivatableImage(GLFWSplashScreen.class.getResource("/splash/splash_5.png"), 630, 0, TerasologyEngineStatus.INITIALIZING_ASSET_MANAGEMENT.getDescription()));
widgets.add(new Image(GLFWSplashScreen.class.getResource("/splash/splash_text.png"), 0, 0));
widgets.add(new BorderedRectangle(pixel, 20, 20, 600, 30));
widgets.add(new AnimatedBoxRow(pixel, 20 + 450 + 10, 20, 600 - 450 - 20, 30));
} catch (IOException e) {
throw new RuntimeException("Cannot load splash image resources");
}
Renderer renderer = new Renderer();
renderer.init();
countDownLatch.countDown();
GL11.glClearColor(0f, 0f, 0f, 0f);
double last = GLFW.glfwGetTime();
try {
while (!isClosing && !window.isClosing()) {
double dTime = GLFW.glfwGetTime() - last;
last = GLFW.glfwGetTime();
renderer.clear();
widgets.forEach(widget -> widget.update(dTime));
widgets.forEach(i -> i.render(renderer));
renderer.drawText(message, 30, 25, Color.BLACK);
window.update();
}
} finally {
widgets.stream().filter(w -> w instanceof Image).map(w -> (Image) w).forEach(Image::delete);
pixel.delete();
renderer.dispose();
window.destroy();
}
}
use of org.lwjgl.opengl.GL11.glViewport in project runelite by runelite.
the class ModelViewer method main.
public static void main(String[] args) throws Exception {
Options options = new Options();
options.addOption(null, "npcdir", true, "npc directory");
options.addOption(null, "mapdir", true, "maps directory");
options.addOption(null, "objectdir", true, "objects directory");
options.addOption(null, "npc", true, "npc to render");
options.addOption(null, "object", true, "object to render");
options.addOption(null, "model", true, "model to render");
options.addOption(null, "map", true, "map region to render");
options.addOption(null, "kits", true, "kits to render");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
String npcdir = cmd.getOptionValue("npcdir");
String mapdir = cmd.getOptionValue("mapdir");
String objectdir = cmd.getOptionValue("objectdir");
NpcDefinition npcdef = null;
ObjectDefinition objdef = null;
List<ModelDefinition> models = new ArrayList<>();
Region region = null;
if (cmd.hasOption("model")) {
// render model
String model = cmd.getOptionValue("model");
ModelDefinition md = ModelManager.getModel(Integer.parseInt(model), null, null);
models.add(md);
}
if (cmd.hasOption("npc")) {
String npc = cmd.getOptionValue("npc");
try (FileInputStream fin = new FileInputStream(npcdir + "/" + npc + ".json")) {
npcdef = new Gson().fromJson(new InputStreamReader(fin), NpcDefinition.class);
}
for (int model : npcdef.models) {
ModelDefinition md = ModelManager.getModel(model, null, null);
models.add(md);
}
}
if (cmd.hasOption("object")) {
String obj = cmd.getOptionValue("object");
try (FileInputStream fin = new FileInputStream(objectdir + "/" + obj + ".json")) {
objdef = new Gson().fromJson(new InputStreamReader(fin), ObjectDefinition.class);
}
for (int model : objdef.getObjectModels()) {
ModelDefinition md = ModelManager.getModel(model, null, null);
models.add(md);
}
}
if (cmd.hasOption("map")) {
String map = cmd.getOptionValue("map");
String[] s = map.split(",");
int x = Integer.parseInt(s[0]), y = Integer.parseInt(s[1]);
region = new Region(x, y);
MapLoader mapLoader = new MapLoader();
LocationsLoader locationsLoader = new LocationsLoader();
try (FileInputStream fin = new FileInputStream(mapdir + "/m" + x + "_" + y + ".dat")) {
byte[] b = IOUtils.toByteArray(fin);
MapDefinition mapDef = mapLoader.load(x, y, b);
region.loadTerrain(mapDef);
}
try (FileInputStream fin = new FileInputStream(mapdir + "/l" + x + "_" + y + ".dat")) {
byte[] b = IOUtils.toByteArray(fin);
LocationsDefinition locDef = locationsLoader.load(x, y, b);
region.loadLocations(locDef);
} catch (FileNotFoundException ex) {
logger.info("No landscape file for {},{}", x, y);
}
loadUnderlays();
loadOverlays();
}
if (cmd.hasOption("kits")) {
String kits = cmd.getOptionValue("kits");
Integer[] kitIds = Arrays.stream(kits.split(",")).map(s -> Integer.parseInt(s)).toArray(Integer[]::new);
for (int kitId : kitIds) {
KitDefinition kit = KitManager.getKit(kitId);
for (int model : kit.modelIds) {
ModelDefinition md = ModelManager.getModel(model, null, null);
models.add(md);
}
}
}
Display.setDisplayMode(new DisplayMode(800, 600));
Display.setTitle("Model Viewer");
Display.setInitialBackground((float) Color.gray.getRed() / 255f, (float) Color.gray.getGreen() / 255f, (float) Color.gray.getBlue() / 255f);
Display.create();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
double aspect = 1;
// near should be chosen as far into the scene as possible
double near = 1;
double far = 10000;
// 1 gives you a 90° field of view. It's tan(fov_angle)/2.
double fov = 1;
GL11.glFrustum(-aspect * near * fov, aspect * near * fov, -fov, fov, near, far);
GL11.glPopMatrix();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glCullFace(GL11.GL_BACK);
GL11.glEnable(GL11.GL_CULL_FACE);
long last = 0;
Camera camera = new Camera();
while (!Display.isCloseRequested()) {
// Clear the screen and depth buffer
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
for (ModelDefinition def : models) {
short[] recolourToFind = null, recolourToReplace = null;
if (npcdef != null) {
recolourToFind = npcdef.recolorToFind;
recolourToReplace = npcdef.recolorToReplace;
}
if (objdef != null) {
recolourToFind = objdef.getRecolorToFind();
recolourToReplace = objdef.getRecolorToReplace();
}
drawModel(def, recolourToFind, recolourToReplace);
}
drawRegion(region);
Display.update();
// fps
Display.sync(50);
long delta = System.currentTimeMillis() - last;
last = System.currentTimeMillis();
camera.acceptInput(delta);
camera.apply();
}
Display.destroy();
}
Aggregations