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

The following examples show how to use org.lwjgl.opengl.GL11#glOrtho() . 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: Overlay.java    From The-5zig-Mod with MIT License 6 votes vote down vote up
private void updateScale() {
	GL11.glViewport(0, 0, mc.d, mc.e);
	GLUtil.matrixMode(GL11.GL_PROJECTION);
	GLUtil.loadIdentity();
	GLUtil.matrixMode(GL11.GL_MODELVIEW);
	GLUtil.loadIdentity();
	this.width = this.mc.d;
	this.height = this.mc.e;
	bca scaledResolution = new bca(this.mc, mc.d, mc.e);
	this.width = scaledResolution.a();
	this.height = scaledResolution.b();
	GLUtil.clear(256);
	GLUtil.matrixMode(GL11.GL_PROJECTION);
	GLUtil.loadIdentity();
	GL11.glOrtho(0.0D, (double) width, (double) height, 0.0D, 1000.0D, 3000.0D);
	GLUtil.matrixMode(GL11.GL_MODELVIEW);
	GLUtil.loadIdentity();
	GLUtil.translate(0.0F, 0.0F, -2000.0F);
}
 
Example 2
Source File: PerspectiveCalculator.java    From ldparteditor with MIT License 6 votes vote down vote up
/**
 * Initializes the viewport and perspective
 */
public void initializeViewportPerspective() {
    if (c3d.getRenderer() instanceof OpenGLRenderer20) {
        // MARK OpenGL Viewport and Perspective
        Rectangle bounds = c3d.getBounds();
        Rectangle scaledBounds = c3d.getScaledBounds();
        GL11.glViewport(0, 0, scaledBounds.width, scaledBounds.height);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        float viewport_width = bounds.width / View.PIXEL_PER_LDU / 2.0f;
        float viewport_height = bounds.height / View.PIXEL_PER_LDU / 2.0f;
        GL11.glOrtho(-viewport_width, viewport_width, -viewport_height, viewport_height, c3d.getzNear() * c3d.getZoom(), c3d.getzFar() * c3d.getZoom());
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();
    }
    calculateOriginData();
}
 
Example 3
Source File: FontHelper.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 6 votes vote down vote up
private static void set2DMode(FloatBuffer matrixData) {
    Minecraft mc = Minecraft.getMinecraft();
    ScaledResolution sr = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
    mc.entityRenderer.setupOverlayRendering();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glPushMatrix();
    //GL11.glLoadMatrix(matrixData);

    GL11.glLoadIdentity();
    GL11.glOrtho(0, mc.displayWidth, 0, mc.displayHeight, -1, 1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();

    Matrix4f matrix = new Matrix4f();
    matrix.load(matrixData);
    GL11.glTranslatef(matrix.m30*sr.getScaleFactor(),-matrix.m31*sr.getScaleFactor(), 0f);

}
 
Example 4
Source File: SlytherClient.java    From Slyther with MIT License 5 votes vote down vote up
private void setupDisplay() {
    int width = Display.getWidth();
    int height = Display.getHeight();
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glScissor(0, 0, width, height);
    GL11.glViewport(0, 0, width, height);
    renderHandler.init();
}
 
Example 5
Source File: LWJGL15DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
public void resize(int width, int height) {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	// coordinate system origin at lower left with width and height same as
	// the window
	GL11.glOrtho(0, width, 0, height, -1, 1);

	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glLoadIdentity();
	GL11.glViewport(0, 0, width, height);
}
 
Example 6
Source File: MatrixUtil.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void testOrthoMatrix(final int left, final int right, final int bottom, final int top, final int near, final int far)
{
	// Make an ortho matrix in opengl and pull it out into a Matrix4f
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glLoadIdentity();
	GL11.glOrtho(left, right, bottom, top, near, far);
	FloatBuffer fromGlBuffer = BufferUtils.createFloatBuffer(16);
	GL11.glGetFloat(GL11.GL_MODELVIEW, fromGlBuffer);
	Matrix4f fromGl = new Matrix4f();
	fromGl.load(fromGlBuffer);
	
	Matrix4f manual = createOrthoMatrix(left, right, bottom, top, near, far);
	
	compare(fromGl, manual);
}
 
Example 7
Source File: ImmediateModeOGLRenderer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.opengl.renderer.SGL#enterOrtho(int, int)
 */
public void enterOrtho(int xsize, int ysize) {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	GL11.glOrtho(0, width, height, 0, 1, -1);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	
	GL11.glTranslatef((width-xsize)/2,
					  (height-ysize)/2,0);
}
 
Example 8
Source File: PBufferGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Enter the orthographic mode 
 */
protected void enterOrtho() {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	GL11.glOrtho(0, screenWidth, 0, screenHeight, 1, -1);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
 
Example 9
Source File: FBOGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Enter the orthographic mode 
 */
protected void enterOrtho() {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	GL11.glOrtho(0, screenWidth, 0, screenHeight, 1, -1);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
 
Example 10
Source File: PBufferUniqueGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Enter the orthographic mode 
 */
protected void enterOrtho() {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	GL11.glOrtho(0, screenWidth, 0, screenHeight, 1, -1);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
 
Example 11
Source File: TestUtils.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialise the GL display
 * 
 * @param width The width of the display
 * @param height The height of the display
 */
private void initGL(int width, int height) {
	try {
		Display.setDisplayMode(new DisplayMode(width,height));
		Display.create();
		Display.setVSyncEnabled(true);
	} catch (LWJGLException e) {
		e.printStackTrace();
		System.exit(0);
	}

	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glShadeModel(GL11.GL_SMOOTH);        
	GL11.glDisable(GL11.GL_DEPTH_TEST);
	GL11.glDisable(GL11.GL_LIGHTING);                    
       
	GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                
       GL11.glClearDepth(1);                                       
       
       GL11.glEnable(GL11.GL_BLEND);
       GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
       
       GL11.glViewport(0,0,width,height);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);

	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glLoadIdentity();
	GL11.glOrtho(0, width, height, 0, 1, -1);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
 
Example 12
Source File: Renderer.java    From AnyaBasic with MIT License 4 votes vote down vote up
Renderer( int screenWidth, int screenHeight )
{
    try
    {
        Display.setDisplayMode(new DisplayMode(screenWidth, screenHeight));
        Display.create();
        Display.setTitle( "AnyaBasic 0.4.0 beta" );
    }
    catch( LWJGLException e )
    {
        e.printStackTrace();
    }

    this.screenWidth = screenWidth;
    this.screenHeight = screenHeight;

    GL11.glViewport( 0, 0,
            screenWidth, screenHeight );

    GL11.glMatrixMode( GL11.GL_PROJECTION );
    GL11.glLoadIdentity();

    GL11.glOrtho( 0, screenWidth, screenHeight, 0, 1, -1 );
    GL11.glMatrixMode( GL11.GL_MODELVIEW );

    GL11.glLoadIdentity();

    GL11.glShadeModel(GL11.GL_SMOOTH);             //set shading to smooth(try GL_FLAT)
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);     //set Clear color to BLACK
    GL11.glClearDepth(1.0f);                       //Set Depth buffer to 1(z-Buffer)
    GL11.glDisable(GL11.GL_DEPTH_TEST);            //Disable Depth Testing so that our z-buffer works

    GL11.glDepthFunc(GL11.GL_LEQUAL);

    GL11.glEnable(GL11.GL_COLOR_MATERIAL);


    GL11.glEnable(GL11.GL_TEXTURE_2D);

    GL11.glEnable( GL11.GL_ALPHA_TEST );
    GL11.glAlphaFunc(GL11.GL_GREATER, 0);

    GL11.glEnable( GL11.GL_BLEND );
    GL11.glBlendFunc( GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA );

    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

    GL11.glDisable(GL11.GL_CULL_FACE);

    GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);

    GL11.glMatrixMode( GL11.GL_MODELVIEW );
    GL11.glLoadIdentity();
    GL11.glTranslatef( 0.375f, 0.375f, 0 );	// magic trick

}
 
Example 13
Source File: IslandGenerator.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
private final static Texture[][] blendTextures(OffscreenRendererFactory factory, int chunks_per_colormap, BlendInfo[] blend_infos, int alpha_size, int structure_size, int scale) {
		boolean use_pbuffer = Settings.getSettings().usePbuffer();
		boolean use_fbo = Settings.getSettings().useFBO();
		OffscreenRenderer offscreen = factory.createRenderer(TEXELS_PER_CHUNK, TEXELS_PER_CHUNK, new PixelFormat(Globals.VIEW_BIT_DEPTH, 0, 0, 0, 0), Settings.getSettings().use_copyteximage, use_pbuffer, use_fbo);
		GL11.glColor4f(1f, 1f, 1f, 1f);
		GL11.glDisable(GL11.GL_DEPTH_TEST);
		GL11.glMatrixMode(GL11.GL_PROJECTION);
		GL11.glLoadIdentity();
		GL11.glOrtho(0f, TEXELS_PER_CHUNK, 0, TEXELS_PER_CHUNK, -1f, 1f);

		GL11.glMatrixMode(GL11.GL_TEXTURE);
		GLState.activeTexture(GL13.GL_TEXTURE1);
		GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
		GL11.glLoadIdentity();
		GLState.activeTexture(GL13.GL_TEXTURE0);
		GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_REPLACE);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
		GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
		GL11.glLoadIdentity();
		GL11.glMatrixMode(GL11.GL_MODELVIEW);

		float alpha_texel_size = 1f/(alpha_size*scale);
		float structure_texel_size = 1f/structure_size;
		float structure_texels_per_chunk_border = Globals.TEXELS_PER_CHUNK_BORDER*structure_texel_size;
		float structure_offset = TEXELS_PER_CHUNK*structure_texel_size - 2*structure_texels_per_chunk_border;
		float structure_length = structure_offset + 2*structure_texels_per_chunk_border;

		float alpha_texels_per_chunk_border = Globals.TEXELS_PER_CHUNK_BORDER*alpha_texel_size;
		float alpha_offset = TEXELS_PER_CHUNK*alpha_texel_size;
		float alpha_length = alpha_offset + 2*alpha_texels_per_chunk_border;

		Texture[][] chunk_maps = new Texture[chunks_per_colormap][chunks_per_colormap];
		FloatBuffer coordinates = BufferUtils.createFloatBuffer(4*3);
		coordinates.put(new float[]{0f, 0f, 0f,
									TEXELS_PER_CHUNK, 0f, 0f,
									TEXELS_PER_CHUNK, TEXELS_PER_CHUNK, 0f,
									0f, TEXELS_PER_CHUNK, 0f});
		coordinates.rewind();
		FloatBuffer structure_tex_coords = BufferUtils.createFloatBuffer(4*2);
		FloatBuffer alpha_tex_coords = BufferUtils.createFloatBuffer(4*2);
		GLStateStack.switchState(GLState.VERTEX_ARRAY | GLState.TEXCOORD0_ARRAY | GLState.TEXCOORD1_ARRAY);
		GL11.glVertexPointer(3, 0, coordinates);
		GL11.glTexCoordPointer(2, 0, structure_tex_coords);
		GLState.clientActiveTexture(GL13.GL_TEXTURE1);
		GL11.glTexCoordPointer(2, 0, alpha_tex_coords);
		GLState.clientActiveTexture(GL13.GL_TEXTURE0);
		for (int y = 0; y < chunk_maps.length; y++) {
			for (int x = 0; x < chunk_maps[y].length; x++) {
				chunk_maps[y][x] = new Texture(TEXELS_PER_CHUNK, TEXELS_PER_CHUNK, GL11.GL_LINEAR_MIPMAP_NEAREST, GL11.GL_LINEAR, GL12.GL_CLAMP_TO_EDGE, GL12.GL_CLAMP_TO_EDGE, Globals.NO_MIPMAP_CUTOFF);
				int mip_scale = 1;
				int mip_level = 0;
				int mip_size = TEXELS_PER_CHUNK;
				while (mip_size >= 1) {
					GL11.glLoadIdentity();
					GL11.glScalef(1f/mip_scale, 1f/mip_scale, 1f);
					GL11.glEnable(GL11.GL_BLEND);

					for (int i = 0; i < blend_infos.length; i++) {
						blend_infos[i].setup();
						float structure_offset_u = x*structure_offset - structure_texels_per_chunk_border;
						float structure_offset_v = y*structure_offset - structure_texels_per_chunk_border;
						float alpha_offset_u = x*alpha_offset - alpha_texels_per_chunk_border;
						float alpha_offset_v = y*alpha_offset - alpha_texels_per_chunk_border;
						structure_tex_coords.put(0, structure_offset_u).put(1, structure_offset_v);
						structure_tex_coords.put(2, structure_offset_u + structure_length).put(3, structure_offset_v);
						structure_tex_coords.put(4, structure_offset_u + structure_length).put(5, structure_offset_v + structure_length);
						structure_tex_coords.put(6, structure_offset_u).put(7, structure_offset_v + structure_length);
						alpha_tex_coords.put(0, alpha_offset_u).put(1, alpha_offset_v);
						alpha_tex_coords.put(2, alpha_offset_u + alpha_length).put(3, alpha_offset_v);
						alpha_tex_coords.put(4, alpha_offset_u + alpha_length).put(5, alpha_offset_v + alpha_length);
						alpha_tex_coords.put(6, alpha_offset_u).put(7, alpha_offset_v + alpha_length);
						GL11.glDrawArrays(GL11.GL_QUADS, 0, 4);
						blend_infos[i].reset();
					}
/*if (mip_level == 0)
offscreen.dumpToFile("colormap-" + x + "-" + y);*/
					offscreen.copyToTexture(chunk_maps[y][x], mip_level, Globals.COMPRESSED_RGB_FORMAT, 0, 0, mip_size, mip_size);
					mip_scale <<= 1;
					mip_level++;
					mip_size >>= 1;
				}
			}
		}
		boolean succeeded = offscreen.destroy();
		if (!succeeded) {
/*			for (int y = 0; y < chunk_maps.length; y++)
				for (int x = 0; x < chunk_maps[y].length; x++)
					chunk_maps[y][x].delete();*/
			return null;
		} else
			return chunk_maps;
	}
 
Example 14
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();

}