Java Code Examples for org.lwjgl.opengl.GL11#glClear()

The following examples show how to use org.lwjgl.opengl.GL11#glClear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: vboWithRGBA.java    From ldparteditor with MIT License 6 votes vote down vote up
@Override
public void drawScene(float mouseX, float mouseY) {
    final GLCanvas canvas = cp.getCanvas();

    if (!canvas.isCurrent()) {
        canvas.setCurrent();
        GL.setCapabilities(cp.getCapabilities());
    }
    
    GL11.glColorMask(true, true, true, true);

    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
    
    Rectangle bounds = cp.getBounds();
    GL11.glViewport(0, 0, bounds.width, bounds.height);
    
    shaderProgram.use();
    GL30.glBindVertexArray(VAO);
    GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 3);
    GL30.glBindVertexArray(0);
    
    canvas.swapBuffers();
}
 
Example 2
Source File: GlassesHUD.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
private void render2D(){
    Minecraft minecraft = FMLClientHandler.instance().getClient();
    EntityPlayer player = minecraft.player;
    ItemStack helmetStack = player.inventory.armorInventory.get(3);
    if(!helmetStack.isEmpty() && minecraft.inGameHasFocus && helmetStack.getItem() == Items.DIAMOND_HELMET) {
        GL11.glDepthMask(false);
        GL11.glDisable(GL11.GL_CULL_FACE);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glPushMatrix();
        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glColor4d(0, 1, 0, 0.8D);

        GL11.glPopMatrix();
        GL11.glEnable(GL11.GL_CULL_FACE);
        GL11.glDepthMask(true);
        GL11.glEnable(GL11.GL_TEXTURE_2D);

        for(int i = 0; i < messages.size(); i++) {
            minecraft.fontRenderer.drawString(messages.get(i).localizedMessage, 16, 16 + i * (minecraft.fontRenderer.FONT_HEIGHT + 1), 0xFF0000);
        }
    }
}
 
Example 3
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst) {
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	}
	final int mirrors = OPTION_DANCE_MIRROR.state ? this.mirrors : 1;
	for (int i = 0; i < mirrors; i++) {
		if (pointsToRender == null) {
			renderCurve(from, to, i);
		} else {
			renderCurve(i);
		}
		//from++;
		//to++;
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 4
Source File: Window.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public void update() {
	if (isResized) {
		GL11.glViewport(0, 0, width, height);
		isResized = false;
	}
	GL11.glClearColor(background.getX(), background.getY(), background.getZ(), 1.0f);
	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	GLFW.glfwPollEvents();
	frames++;
	if (System.currentTimeMillis() > time + 1000) {
		GLFW.glfwSetWindowTitle(window, title + " | FPS: " + frames);
		time = System.currentTimeMillis();
		frames = 0;
	}
}
 
Example 5
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Do the actual drawing of the curve into the currently bound framebuffer.
 * @param color the color of the curve
 * @param borderColor the curve border color
 */
private void renderCurve(Color color, Color borderColor, int from, int to, boolean clearFirst) {
	staticState.initGradient();
	RenderState state = saveRenderState();
	staticState.initShaderProgram();
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, fbo.getVbo());
	GL20.glUseProgram(staticState.program);
	GL20.glEnableVertexAttribArray(staticState.attribLoc);
	GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
	GL20.glUniform1i(staticState.texLoc, 0);
	GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
	GL20.glUniform4f(staticState.colBorderLoc, borderColor.r, borderColor.g, borderColor.b, borderColor.a);
	//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
	//2*4 is for skipping the first 2 floats (u,v)
	GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
	GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
	if (clearFirst)
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	if (pointsToRender == null) {
		for (int i = from * 2; i < to * 2 - 1; ++i) {
			if (spliceFrom <= i && i <= spliceTo)
				continue;
			GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	} else {
		Iterator<Integer> iter = pointsToRender.iterator();
		while (iter.hasNext()) {
			for (int i = iter.next() * 2, end = iter.next() * 2 - 1; i < end; ++i)
				GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
		}
	}
	GL11.glFlush();
	GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
	GL20.glDisableVertexAttribArray(staticState.attribLoc);
	restoreRenderState(state);
}
 
Example 6
Source File: GUI.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public final void render(AmbientAudio ambient, CameraState frustum_state) {
	boolean clear_color = renderer != null ? renderer.clearColorBuffer() : true;
	if (clear_color)
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
	else
		GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
	if (renderer != null)
		renderer.render(ambient, frustum_state, current_root);
	renderGUI();
}
 
Example 7
Source File: TranslateTool.java    From Mundus with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
    super.render();
    if (getProjectManager().current().currScene.currentSelection != null) {
        getBatch().begin(getProjectManager().current().currScene.cam);
        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        xHandle.render(getBatch());
        yHandle.render(getBatch());
        zHandle.render(getBatch());
        xzPlaneHandle.render(getBatch());

        getBatch().end();
    }
}
 
Example 8
Source File: Test.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final static void main(String[] args) {
		try {
			Display.setDisplayMode(new DisplayMode(DISPLAY_WIDTH, DISPLAY_HEIGHT));
			Display.create();
			initGL();

			// Load font
			InputStream font_is = Utils.makeURL("/fonts/tahoma.ttf").openStream();
			java.awt.Font src_font = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, font_is);
			java.awt.Font font = src_font.deriveFont(14f);

			// Load text
			InputStreamReader text_is = new InputStreamReader(Utils.makeURL("/test_text.txt").openStream());
			StringBuffer str_buffer = new StringBuffer();
			int c = text_is.read();
			do {
				str_buffer.append((char)c);
				c = text_is.read();
			} while (c != -1);
			String str = str_buffer.toString();

			// Build texture
			int[] pixels = new int[WIDTH*HEIGHT];
//			ByteBuffer pixel_data = ByteBuffer.wrap(pixels);						// NEW
//			pixelDataFromString(WIDTH, HEIGHT, str, font, pixels);					// NEW
			IntBuffer pixel_data = BufferUtils.createIntBuffer(WIDTH*HEIGHT);	// OLD
			pixel_data.put(pixels);													// OLD
			pixel_data.rewind();

			int texture_handle = createTexture(WIDTH, HEIGHT, pixel_data);
			
		FontRenderContext frc = g2d.getFontRenderContext();
		AttributedString att_str = new AttributedString(str);
		att_str.addAttribute(TextAttribute.FONT, font);
		AttributedCharacterIterator iterator = att_str.getIterator();
		LineBreakMeasurer measurer = new LineBreakMeasurer(iterator, frc);
		
			while (!Display.isCloseRequested()) {
long start_time = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
pixelDataFromString(WIDTH, HEIGHT, str, font, pixels, measurer);
pixel_data.put(pixels); // OLD
pixel_data.rewind();

//texture_handle = createTexture(WIDTH, HEIGHT, pixel_data);
updateTexture(WIDTH, HEIGHT, pixel_data);
				GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
				GL11.glLoadIdentity();
				
				// Background
				/*
				GL11.glDisable(GL11.GL_TEXTURE_2D);
				GL11.glColor4f(.1f, .1f, .1f, 1f);
				GL11.glBegin(GL11.GL_QUADS);
				GL11.glVertex3f(0f, DISPLAY_HEIGHT-RENDER_SIZE, 1f);
				GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT-RENDER_SIZE, 1f);
				GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT, 1f);
				GL11.glVertex3f(0f, DISPLAY_HEIGHT, 1f);
				GL11.glEnd();
				*/

				// Text
				GL11.glEnable(GL11.GL_TEXTURE_2D);
				GL11.glColor4f(1f, 1f, 1f, 1f);
				GL11.glBegin(GL11.GL_QUADS);
				GL11.glTexCoord2f(0f, 1f);
				GL11.glVertex3f(0f, DISPLAY_HEIGHT-RENDER_SIZE, 1f);
				GL11.glTexCoord2f(1f, 1f);
				GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT-RENDER_SIZE, 1f);
				GL11.glTexCoord2f(1f, 0f);
				GL11.glVertex3f(RENDER_SIZE, DISPLAY_HEIGHT, 1f);
				GL11.glTexCoord2f(0f, 0f);
				GL11.glVertex3f(0f, DISPLAY_HEIGHT, 1f);
				GL11.glEnd();
				Display.update();
}
long total_time = System.currentTimeMillis() - start_time;
System.out.println("total_time = " + total_time);

			}
			Display.destroy();
		} catch (Exception t) {
			t.printStackTrace();
		}
	}
 
Example 9
Source File: ImmediateModeOGLRenderer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see org.newdawn.slick.opengl.renderer.SGL#glClear(int)
 */
public void glClear(int value) {
	GL11.glClear(value);
}
 
Example 10
Source File: Graphics.java    From AnyaBasic with MIT License 4 votes vote down vote up
public void cls()
{
    GL11.glClear( GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT );
}
 
Example 11
Source File: AsyncContextCreator.java    From settlers-remake with MIT License 4 votes vote down vote up
@Override
public void run() {
	async_init();

	parent.wrapNewContext();

	while(continue_run) {
		if (change_res) {
			if(!ignore_resize) {
				width = new_width;
				height = new_height;
				async_set_size(width, height);

				parent.resize_gl(width, height);

				bi = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
				pixels = BufferUtils.createIntBuffer(width * height);
			}
			ignore_resize = false;
			change_res = false;
		}

		async_refresh();

		parent.draw();

		if (offscreen) {
			synchronized (wnd_lock) {
				GL11.glReadPixels(0, 0, width, height, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, pixels);
				for (int x = 0; x != width; x++) {
					for (int y = 0; y != height; y++) {
						bi.setRGB(x, height - y - 1, pixels.get(y * width + x));
					}
				}
			}
		}

		if(!offscreen || clear_offscreen ){
			if(clear_offscreen) {
				GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
				clear_offscreen = false;
			}
			async_swapbuffers();
		}
	}

	async_stop();
}
 
Example 12
Source File: DrawOnDemandTest.java    From lwjgl3-awt with MIT License 4 votes vote down vote up
public static void main(String[] args) {
	
	AWTGLCanvas canvas = new AWTGLCanvas() {
		private static final long serialVersionUID = 1L;

		@Override
		public void initGL() {
			GL.createCapabilities();
			glClearColor(0.3f, 0.4f, 0.5f, 1);
		}
		
		@Override
		public void paintGL() {
			int w = getWidth();
			int h = getHeight();
			if (w == 0 || h == 0) {
				return;
			}
			float aspect = (float) w / h;
			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
			GL11.glViewport(0, 0, w, h);
			GL11.glBegin(GL11.GL_QUADS);
			GL11.glColor3f(quadColor.getRed()/255f, quadColor.getGreen()/255f, quadColor.getBlue()/255f);
			GL11.glVertex2f(-0.75f / aspect, 0.0f);
			GL11.glVertex2f(0, -0.75f);
			GL11.glVertex2f(+0.75f / aspect, 0);
			GL11.glVertex2f(0, +0.75f);
			GL11.glEnd();
			swapBuffers();
		}

		@Override
		public void repaint() {
			if (SwingUtilities.isEventDispatchThread()) {
				render();
			} else {
				SwingUtilities.invokeLater(() -> render());
			}
		}

	};

	JFrame frame = new JFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().setLayout(new BorderLayout());
	frame.getContentPane().add(canvas, BorderLayout.CENTER);
	canvas.setPreferredSize(new Dimension(200, 200));
	canvas.addComponentListener(new ComponentAdapter() {
		public void componentResized(java.awt.event.ComponentEvent e) {
			canvas.repaint();
		};
	});
	JColorChooser colorChooser = new JColorChooser(quadColor);
	frame.getContentPane().add(colorChooser, BorderLayout.SOUTH);
	colorChooser.getSelectionModel().addChangeListener((e)->{
		quadColor = colorChooser.getColor();
		canvas.repaint();
	});
	

	SwingUtilities.invokeLater(() -> {
		frame.pack();
		frame.setVisible(true);
	});
}
 
Example 13
Source File: Renderer.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
public final static void clearScreen() {
	GL11.glClearColor(0f, 0f, 0f, 0f);
	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
	//GL11.glClearColor(1f, 0f, 1f, 0f);
}
 
Example 14
Source File: SelfEnd.java    From ehacks-pro with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onWorldRender(RenderWorldLastEvent event) {
    if (selectedEnt == null) {
        return;
    }
    if (distVec != null) {
        distVec = Wrapper.INSTANCE.mc().renderViewEntity.getLookVec().normalize();
        distVec.xCoord *= size;
        distVec.yCoord *= size;
        distVec.zCoord *= size;
    }
    NBTTagCompound tag = new NBTTagCompound();
    selectedEnt.writeToNBT(tag);

    if (!GLUtils.hasClearedDepth) {
        GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
        GLUtils.hasClearedDepth = true;
    }
    Entity ent = selectedEnt;

    double tXPos = ent.posX;
    double tYPos = ent.posY;
    double tZPos = ent.posZ;

    double xPos = (Wrapper.INSTANCE.mc().renderViewEntity.lastTickPosX + distVec.xCoord) + (Wrapper.INSTANCE.mc().renderViewEntity.posX - Wrapper.INSTANCE.mc().renderViewEntity.lastTickPosX) * event.partialTicks;
    double yPos = (Wrapper.INSTANCE.mc().renderViewEntity.lastTickPosY + distVec.yCoord + 1) + (Wrapper.INSTANCE.mc().renderViewEntity.posY - Wrapper.INSTANCE.mc().renderViewEntity.lastTickPosY) * event.partialTicks;
    double zPos = (Wrapper.INSTANCE.mc().renderViewEntity.lastTickPosZ + distVec.zCoord) + (Wrapper.INSTANCE.mc().renderViewEntity.posZ - Wrapper.INSTANCE.mc().renderViewEntity.lastTickPosZ) * event.partialTicks;

    ent.posX = ent.lastTickPosX = xPos;
    ent.posY = ent.lastTickPosY = yPos;
    ent.posZ = ent.lastTickPosZ = zPos;

    float f1 = ent.prevRotationYaw + (ent.rotationYaw - ent.prevRotationYaw) * event.partialTicks;
    RenderHelper.enableStandardItemLighting();
    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F);
    if (Wrapper.INSTANCE.world().loadedEntityList.contains(selectedEnt)) {
        GL11.glColor4f(0, 1.0F, 0, 1f);
    } else {
        GL11.glColor4f(1.0F, 0, 0, 1f);
    }
    RenderManager.instance.func_147939_a(ent, xPos - renderPosX, yPos - renderPosY, zPos - renderPosZ, f1, event.partialTicks, false);

    ent.posX = ent.lastTickPosX = tXPos;
    ent.posY = ent.lastTickPosY = tYPos;
    ent.posZ = ent.lastTickPosZ = tZPos;

    OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
 
Example 15
Source File: StenciledTextureRenderer.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void render(RenderGlobal context, float partialTickTime) {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glPushMatrix();
	GL11.glLoadIdentity();

	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glPushMatrix();
	GL11.glLoadIdentity();

	GL11.glOrtho(-1, +1, -1, +1, -1, +1);

	GL11.glEnable(GL11.GL_STENCIL_TEST);
	GL11.glStencilMask(stencilMask);
	GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
	GL11.glStencilFunc(GL11.GL_EQUAL, stencilMask, stencilMask);

	TextureUtils.bindTextureToClient(texture);

	RenderUtils.disableLightmap();
	GlStateManager.disableLighting();

	GlStateManager.color(1, 1, 1);

	GL11.glBegin(GL11.GL_QUADS);
	GL11.glTexCoord2f(0, 0);
	GL11.glVertex3f(-1, -1, 0);

	GL11.glTexCoord2f(1, 0);
	GL11.glVertex3f(+1, -1, 0);

	GL11.glTexCoord2f(1, 1);
	GL11.glVertex3f(+1, +1, 0);

	GL11.glTexCoord2f(0, 1);
	GL11.glVertex3f(-1, +1, 0);

	GL11.glEnd();

	// mask should prevent this command from clearing other bits
	GL11.glClearStencil(0);
	GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);

	GL11.glDisable(GL11.GL_STENCIL_TEST);

	RenderUtils.enableLightmap();
	GlStateManager.enableLighting();

	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glPopMatrix();

	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glPopMatrix();

}
 
Example 16
Source File: RenderCoordWireframe.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
public void render(float partialTicks){
    /*
    Block block = Block.blocksList[world.getBlockId(x, y, z)];
    block.setBlockBoundsBasedOnState(world, x, y, z);
    double minX = block.getBlockBoundsMinX();
    double minY = block.getBlockBoundsMinY();
    double minZ = block.getBlockBoundsMinZ();
    double maxX = minX + (block.getBlockBoundsMaxX() - minX) * progress;
    double maxY = minY + (block.getBlockBoundsMaxY() - minY) * progress;
    double maxZ = minZ + (block.getBlockBoundsMaxX() - minZ) * progress;
    */
    double minX = 0;
    double minY = 0;
    double minZ = 0;
    double maxX = 1;
    double maxY = 1;
    double maxZ = 1;
    float progress = (ticksExisted % 20 + partialTicks) / 20;
    GL11.glDepthMask(false);
    GL11.glDisable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glDisable(GL11.GL_TEXTURE_2D);
    GL11.glLineWidth(1.0F);
    // GL11.glColor4d(0, 1, 1, progress < 0.5F ? progress + 0.5F : 1.5 - progress);
    GL11.glColor4d(0, progress < 0.5F ? progress + 0.5F : 1.5 - progress, 1, 1);
    GL11.glPushMatrix();
    // GL11.glTranslated(-0.5D, -0.5D, -0.5D);
    GL11.glTranslated(x, y, z);
    Tessellator tess = Tessellator.instance;

    tess.startDrawing(GL11.GL_LINES);
    tess.addVertex(minX, minY, minZ);
    tess.addVertex(minX, maxY, minZ);
    tess.addVertex(minX, minY, maxZ);
    tess.addVertex(minX, maxY, maxZ);

    tess.addVertex(maxX, minY, minZ);
    tess.addVertex(maxX, maxY, minZ);
    tess.addVertex(maxX, minY, maxZ);
    tess.addVertex(maxX, maxY, maxZ);

    tess.addVertex(minX, minY, minZ);
    tess.addVertex(maxX, minY, minZ);
    tess.addVertex(minX, minY, maxZ);
    tess.addVertex(maxX, minY, maxZ);

    tess.addVertex(minX, maxY, minZ);
    tess.addVertex(maxX, maxY, minZ);
    tess.addVertex(minX, maxY, maxZ);
    tess.addVertex(maxX, maxY, maxZ);

    tess.addVertex(minX, minY, minZ);
    tess.addVertex(minX, minY, maxZ);
    tess.addVertex(maxX, minY, minZ);
    tess.addVertex(maxX, minY, maxZ);

    tess.addVertex(minX, maxY, minZ);
    tess.addVertex(minX, maxY, maxZ);
    tess.addVertex(maxX, maxY, minZ);
    tess.addVertex(maxX, maxY, maxZ);

    tess.draw();

    GL11.glPopMatrix();
    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_TEXTURE_2D);
}
 
Example 17
Source File: OffscreenBuffer.java    From LWJGUI with MIT License 4 votes vote down vote up
public void drawClearDepth() {
	GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT);
}
 
Example 18
Source File: OffscreenBuffer.java    From LWJGUI with MIT License 4 votes vote down vote up
public void drawClearColorDepth(Color color) {
	GL11.glClearColor(color.getRedF(), color.getGreenF(), color.getBlueF(), color.getAlphaF());
	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPTH_BUFFER_BIT);
}
 
Example 19
Source File: OffscreenBuffer.java    From LWJGUI with MIT License 4 votes vote down vote up
public void drawClearColor(Color color) {
	GL11.glClearColor(color.getRedF(), color.getGreenF(), color.getBlueF(), color.getAlphaF());
	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
}
 
Example 20
Source File: OpenGLPane.java    From LWJGUI with MIT License 4 votes vote down vote up
@Override
public void render(Context context) {
	if ( !isVisible() )
		return;
	
	// Check for resize
	Vector2i newDims = new Vector2i((int)getWidth(),(int)getHeight());
	if ( !newDims.equals(oldSize) || nanoImage == -1 ) {
		oldSize.set(newDims);
		resizeBuffer();
	}
	
	// FBO Rendering
	if ( renderer != null && nanoImage != -1 ) {
		NanoVG.nvgSave(context.getNVG());
		//NanoVG.nvgEndFrame(context.getNVG());
		{
			// Bind & render to FBO
			this.buffer.bind();
			{
				// Background fill
				if ( this.internalBackground != null && isAutoClear() ) {
					float r = internalBackground.getRed()/255f;
					float g = internalBackground.getGreen()/255f;
					float b = internalBackground.getBlue()/255f;
					GL11.glClearColor(r, g, b, 1);
					GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPTH_BUFFER_BIT);
				}
				
				// Viewport
				GL11.glViewport(0, 0, (int)getWidth(), (int)getHeight());
				
				// Drawing
				NanoVG.nvgBeginFrame(internalContext.getNVG(), (int)getWidth(), (int)getHeight(), window.getPixelRatio());
				//internalContext.refresh(context);
				renderer.render(internalContext, (int)getWidth(), (int)getHeight());
				NanoVG.nvgEndFrame(internalContext.getNVG());
			}
			this.buffer.unbind();
		}
		
		// Restore nanovg
		NanoVG.nvgRestore(context.getNVG());
		context.refresh(); // Restore glViewport

		// Render FBO to screen
		long nanovg = context.getNVG();
		float x = (int)this.getX();
		float y = (int)this.getY();
		float w = (int)this.getWidth();
		float h = (int)this.getHeight();
		if ( flipY ) {
			y = y + h;
			h = -h;
		}
		try (MemoryStack stack = stackPush()) {
			NVGPaint imagePaint = NanoVG.nvgImagePattern(nanovg, x, y, w, h, 0, nanoImage, 1, NVGPaint.callocStack(stack));
			NanoVG.nvgBeginPath(nanovg);
			NanoVG.nvgRect(nanovg, x, y, w, h);
			NanoVG.nvgFillPaint(nanovg, imagePaint);
			NanoVG.nvgFill(nanovg);
		}
	}
	
	// Render children
	super.render(context);
}