use of org.lwjgl.opengl.GL11.glTexParameterf in project BuildCraft by BuildCraft.
the class GuiZonePlanner method drawForegroundLayer.
@SuppressWarnings("PointlessBitwiseExpression")
@Override
protected void drawForegroundLayer() {
camY += scaleSpeed;
scaleSpeed *= 0.7F;
int posX = (int) positionX;
int posZ = (int) positionZ;
int dimension = mc.world.provider.getDimension();
{
ChunkPos chunkPos = new ChunkPos(posX >> 4, posZ >> 4);
ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
BlockPos pos = null;
if (zonePlannerMapChunk != null) {
MapColourData data = zonePlannerMapChunk.getData(posX, posZ);
if (data != null) {
pos = new BlockPos(posX, data.posY, posZ);
}
}
if (pos != null && pos.getY() + 10 > camY) {
camY = Math.max(camY, pos.getY() + 10);
}
}
int x = guiLeft;
int y = guiTop;
if (lastSelected != null) {
String text = "X: " + lastSelected.getX() + " Y: " + lastSelected.getY() + " Z: " + lastSelected.getZ();
fontRenderer.drawString(text, x + 130, y + 130, 0x404040);
}
int offsetX = 8;
int offsetY = 9;
int sizeX = 213;
int sizeY = 100;
GlStateManager.pushMatrix();
GlStateManager.matrixMode(GL11.GL_PROJECTION);
GlStateManager.pushMatrix();
GlStateManager.loadIdentity();
ScaledResolution scaledResolution = new ScaledResolution(mc);
int viewportX = (x + offsetX) * scaledResolution.getScaleFactor();
int viewportY = mc.displayHeight - (sizeY + y + offsetY) * scaledResolution.getScaleFactor();
int viewportWidth = sizeX * scaledResolution.getScaleFactor();
int viewportHeight = sizeY * scaledResolution.getScaleFactor();
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GL11.glScissor(viewportX, viewportY, viewportWidth, viewportHeight);
GlStateManager.clear(GL11.GL_DEPTH_BUFFER_BIT);
GL11.glDisable(GL11.GL_SCISSOR_TEST);
GlStateManager.viewport(viewportX, viewportY, viewportWidth, viewportHeight);
GlStateManager.scale(scaledResolution.getScaleFactor(), scaledResolution.getScaleFactor(), 1);
GLU.gluPerspective(70.0F, (float) sizeX / sizeY, 1F, 10000.0F);
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
GlStateManager.loadIdentity();
RenderHelper.enableStandardItemLighting();
GlStateManager.enableRescaleNormal();
// look down
GlStateManager.rotate(90, 1, 0, 0);
GlStateManager.pushMatrix();
GlStateManager.translate(-positionX, -camY, -positionZ);
GlStateManager.disableBlend();
GlStateManager.disableAlpha();
GlStateManager.disableTexture2D();
int minScreenX = (x + offsetX) * scaledResolution.getScaleFactor();
int minScreenY = (scaledResolution.getScaledHeight() - (y + offsetY)) * scaledResolution.getScaleFactor();
int maxScreenX = (x + offsetX + sizeX) * scaledResolution.getScaleFactor();
int maxScreenY = (scaledResolution.getScaledHeight() - (y + offsetY + sizeY)) * scaledResolution.getScaleFactor();
int minChunkX = (posX >> 4) - 8;
int minChunkZ = (posZ >> 4) - 8;
int maxChunkX = (posX >> 4) + 8;
int maxChunkZ = (posZ >> 4) + 8;
// noinspection SuspiciousNameCombination
List<ChunkPos> chunkPosBounds = Stream.of(Pair.of(minScreenX, minScreenY), Pair.of(minScreenX, maxScreenY), Pair.of(maxScreenX, minScreenY), Pair.of(maxScreenX, maxScreenY)).map(p -> rayTrace(p.getLeft(), p.getRight())).filter(Objects::nonNull).map(ChunkPos::new).collect(Collectors.toList());
for (ChunkPos chunkPos : chunkPosBounds) {
if (chunkPos.x < minChunkX) {
minChunkX = chunkPos.x;
}
if (chunkPos.z < minChunkZ) {
minChunkZ = chunkPos.z;
}
if (chunkPos.x > maxChunkX) {
maxChunkX = chunkPos.x;
}
if (chunkPos.z > maxChunkZ) {
maxChunkZ = chunkPos.z;
}
}
minChunkX--;
minChunkZ--;
maxChunkX++;
maxChunkZ++;
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
ZonePlannerMapRenderer.INSTANCE.getChunkGlList(new ZonePlannerMapChunkKey(new ChunkPos(chunkX, chunkZ), dimension, container.tile.getLevel())).ifPresent(GlStateManager::callList);
}
}
BlockPos found = null;
int foundColor = 0;
if (Mouse.getX() >= minScreenX && Mouse.getY() <= minScreenY && Mouse.getX() <= maxScreenX && Mouse.getY() >= maxScreenY) {
found = rayTrace(Mouse.getX(), Mouse.getY());
}
if (found != null) {
ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(new ChunkPos(found), mc.world.provider.getDimension(), container.tile.getLevel()));
if (zonePlannerMapChunk != null) {
MapColourData data = zonePlannerMapChunk.getData(found.getX(), found.getZ());
if (data != null) {
foundColor = data.colour;
}
}
}
if (found != null) {
GlStateManager.disableDepth();
GlStateManager.enableBlend();
GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
GlStateManager.glLineWidth(2);
int r = (int) (((foundColor >> 16) & 0xFF) * 0.7);
int g = (int) (((foundColor >> 8) & 0xFF) * 0.7);
int b = (int) (((foundColor >> 0) & 0xFF) * 0.7);
int a = 0x77;
ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
BufferBuilder builder = Tessellator.getInstance().getBuffer();
builder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(builder, found.getX(), found.getY(), found.getZ());
Tessellator.getInstance().draw();
GlStateManager.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
GlStateManager.disableBlend();
GlStateManager.enableDepth();
}
GlStateManager.disableLighting();
GlStateManager.enableBlend();
for (int i = 0; i < container.tile.layers.length; i++) {
if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() != i) {
continue;
}
ZonePlan layer = container.tile.layers[i];
if (getPaintbrushBrush() != null && getPaintbrushBrush().colour.getMetadata() == i && bufferLayer != null) {
layer = bufferLayer;
}
if (!layer.getChunkPoses().isEmpty()) {
Tessellator.getInstance().getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
ChunkPos chunkPos = new ChunkPos(chunkX, chunkZ);
for (int blockX = chunkPos.getXStart(); blockX <= chunkPos.getXEnd(); blockX++) {
for (int blockZ = chunkPos.getZStart(); blockZ <= chunkPos.getZEnd(); blockZ++) {
if (!layer.get(blockX - container.tile.getPos().getX(), blockZ - container.tile.getPos().getZ())) {
continue;
}
int height;
ZonePlannerMapChunk zonePlannerMapChunk = ZonePlannerMapDataClient.INSTANCE.getChunk(mc.world, new ZonePlannerMapChunkKey(chunkPos, dimension, container.tile.getLevel()));
if (zonePlannerMapChunk != null) {
MapColourData data = zonePlannerMapChunk.getData(blockX, blockZ);
if (data != null) {
height = data.posY;
} else {
continue;
}
} else {
continue;
}
int color = EnumDyeColor.byMetadata(i).getColorValue();
int r = (color >> 16) & 0xFF;
int g = (color >> 8) & 0xFF;
int b = (color >> 0) & 0xFF;
int a = 0x55;
ZonePlannerMapRenderer.INSTANCE.setColor(r << 16 | g << 8 | b << 0 | a << 24);
ZonePlannerMapRenderer.INSTANCE.drawBlockCuboid(Tessellator.getInstance().getBuffer(), blockX, height + 0.1, blockZ, height, 0.6);
}
}
}
}
Tessellator.getInstance().draw();
}
}
GlStateManager.disableBlend();
GlStateManager.disableLighting();
GlStateManager.enableTexture2D();
lastSelected = found;
GlStateManager.popMatrix();
GlStateManager.disableRescaleNormal();
GlStateManager.matrixMode(GL11.GL_PROJECTION);
GlStateManager.viewport(0, 0, mc.displayWidth, mc.displayHeight);
GlStateManager.popMatrix();
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
GlStateManager.popMatrix();
RenderHelper.disableStandardItemLighting();
GlStateManager.disableBlend();
}
use of org.lwjgl.opengl.GL11.glTexParameterf 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.glTexParameterf 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();
}
use of org.lwjgl.opengl.GL11.glTexParameterf in project LogisticsPipes by RS485.
the class OpenGLDebugger method updateNiceToHave.
private static void updateNiceToHave() {
OpenGLDebugger.niceToHave = new HashMap<>();
int crawlerVersion = 11;
boolean almostEnd = false;
boolean end = false;
while (!end) {
String packageGL = String.format("%s%d", "GL", crawlerVersion);
String nextGL = String.format("%s.%s", "org.lwjgl.opengl", packageGL);
try {
crawlerVersion++;
Class glClass = GL11.class.getClassLoader().loadClass(nextGL);
com.google.common.reflect.Reflection.initialize(glClass);
almostEnd = false;
for (Field f : glClass.getDeclaredFields()) {
try {
if (!f.getType().equals(int.class)) {
continue;
}
int id = f.getInt(null);
String nice = f.getName();
if (nice.endsWith("BIT")) {
continue;
}
// All the things that are being replaced are not that bad
if (OpenGLDebugger.niceToHave.containsKey(id) && !OpenGLDebugger.niceToHave.get(id).equals(nice)) {
System.out.printf("NiceToHave: ID %d exists. Replacing %s with %s!!%n", id, OpenGLDebugger.niceToHave.remove(id), nice);
}
OpenGLDebugger.niceToHave.put(id, String.format("%s.%s", packageGL, nice));
} catch (IllegalArgumentException e) {
System.out.printf("NiceToHave: Illegal Argument!%nNiceToHave: %s%n", e);
e.printStackTrace();
} catch (IllegalAccessException e) {
System.out.printf("NiceToHave: Illegal Access!%nNiceToHave: %s%n", e);
e.printStackTrace();
}
}
} catch (ClassNotFoundException e) {
if (almostEnd) {
end = true;
} else {
almostEnd = true;
crawlerVersion = (crawlerVersion / 10 + 1) * 10;
}
}
}
}
Aggregations