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

The following examples show how to use org.lwjgl.opengl.GL11#glMatrixMode() . 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: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Restore the old OpenGL state that's backed up in {@code state}.
 * @param state the old state to restore
 */
private void restoreRenderState(RenderState state) {
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glPopMatrix();
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glPopMatrix();
	GL11.glEnable(GL11.GL_BLEND);
	GL20.glUseProgram(state.oldProgram);
	GL13.glActiveTexture(state.texUnit);
	GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, state.oldArrayBuffer);
	if (!state.depthWriteEnabled)
		GL11.glDepthMask(false);
	if (!state.depthEnabled)
		GL11.glDisable(GL11.GL_DEPTH_TEST);
	if (state.texEnabled)
		GL11.glEnable(GL11.GL_TEXTURE_2D);
	if (state.smoothedPoly)
		GL11.glEnable(GL11.GL_POLYGON_SMOOTH);
	if (!state.blendEnabled)
		GL11.glDisable(GL11.GL_BLEND);
}
 
Example 2
Source File: SlickCallable.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Leave a safe block ensuring that all of Slick's OpenGL state is
 * restored since the last enter.
 */
public static void leaveSafeBlock() 
{
	if (!inSafe) {
		return;
	}

	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glPopMatrix();
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glPopMatrix();
	GL11.glPopClientAttrib();
	GL11.glPopAttrib();
	
	if (lastUsed != null) {
		lastUsed.bind();
	} else {
		TextureImpl.bindNone();
	}
	
	inSafe = false;
}
 
Example 3
Source File: SlickCallable.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Enter a safe block ensuring that all the OpenGL state that slick 
 * uses is safe before touching the GL state directly.
 */
public static void enterSafeBlock() 
{
	if (inSafe) {
		return;
	}
	
	Renderer.get().flush();
	lastUsed = TextureImpl.getLastBind();
	TextureImpl.bindNone();
	GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
	GL11.glPushClientAttrib(GL11.GL_ALL_CLIENT_ATTRIB_BITS);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glPushMatrix();
	GL11.glMatrixMode(GL11.GL_PROJECTION);
	GL11.glPushMatrix();
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	
	inSafe = true;
}
 
Example 4
Source File: PBufferGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Initialise the GL context
 */
protected void initGL() {
	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,screenWidth,screenHeight);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glLoadIdentity();
	
	enterOrtho();
}
 
Example 5
Source File: ShadowRenderer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
protected static void setupShadows() {
	VBO.releaseIndexVBO();
	GL11.glEnable(GL11.GL_BLEND);
	GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
	GL11.glDepthFunc(GL11.GL_EQUAL);
	GLStateStack.switchState(GLState.VERTEX_ARRAY);
	GL11.glEnable(GL11.GL_TEXTURE_GEN_S);
	GL11.glEnable(GL11.GL_TEXTURE_GEN_T);
	
	// Workaround, See comment in renderShadow
	GL11.glMatrixMode(GL11.GL_TEXTURE);
}
 
Example 6
Source File: RenderUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static void gl11Setup() {
	GL11.glEnable(GL11.GL_BLEND);
       GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
       GL11.glLineWidth(2.5F);
       GL11.glDisable(GL11.GL_TEXTURE_2D);
       GL11.glDisable(GL11.GL_DEPTH_TEST);
       GL11.glMatrixMode(5889);
	GL11.glEnable(GL11.GL_LINE_SMOOTH);
	GL11.glPushMatrix();
}
 
Example 7
Source File: LwjglRasteriser.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setCameraMatrix(Matrix4f matrix, Vector3f lookAt, Vector3f eye, Vector3f up)
{
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
	GL11.glLoadIdentity();
	
	FloatBuffer buffer = BufferUtils.createFloatBuffer(16);
	matrix.store(buffer);
	buffer.flip();
	GL11.glLoadMatrix(buffer);
}
 
Example 8
Source File: Sky.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final void setupSky() {
	float time = LocalEventQueue.getQueue().getTime();
	float speed_scale = 0.01f;
	float outer_dx = SKYDOME_SPEED_OUTER[0] * time*speed_scale;
	float outer_dy = SKYDOME_SPEED_OUTER[1] * time*speed_scale;
	float inner_dx = SKYDOME_SPEED_INNER[0] * time*speed_scale;
	float inner_dy = SKYDOME_SPEED_INNER[1] * time*speed_scale;
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, clouds[GeneratorClouds.INNER].getHandle());
	GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_BLEND);
	GL11.glTexEnv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, color);
	GL11.glMatrixMode(GL11.GL_TEXTURE);
	GL11.glTranslatef(outer_dx, outer_dy, 0);
	GLState.activeTexture(GL13.GL_TEXTURE1);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, clouds[GeneratorClouds.OUTER].getHandle());
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glTranslatef(inner_dx, inner_dy, 0);
	GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_BLEND);
	GL11.glTexEnv(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_COLOR, color);
	

	GLStateStack.switchState(GLState.VERTEX_ARRAY | GLState.COLOR_ARRAY | GLState.TEXCOORD0_ARRAY | GLState.TEXCOORD1_ARRAY);
	sky_vertices.vertexPointer(3, 0, 0);
	sky_tex0.texCoordPointer(2, 0, 0);
	sky_colors.colorPointer(3, 0, 0);
	GLState.clientActiveTexture(GL13.GL_TEXTURE1);
	sky_tex1.texCoordPointer(2, 0, 0);
	GLState.clientActiveTexture(GL13.GL_TEXTURE0);
}
 
Example 9
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 10
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Backup the current state of the relevant OpenGL state and change it to
 * what's needed to draw the curve.
 */
private RenderState saveRenderState() {
	RenderState state = new RenderState();
	state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH);
	state.blendEnabled = GL11.glGetBoolean(GL11.GL_BLEND);
	state.depthEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_TEST);
	state.depthWriteEnabled = GL11.glGetBoolean(GL11.GL_DEPTH_WRITEMASK);
	state.texEnabled = GL11.glGetBoolean(GL11.GL_TEXTURE_2D);
	state.texUnit = GL11.glGetInteger(GL13.GL_ACTIVE_TEXTURE);
	state.oldProgram = GL11.glGetInteger(GL20.GL_CURRENT_PROGRAM);
	state.oldArrayBuffer = GL11.glGetInteger(GL15.GL_ARRAY_BUFFER_BINDING);
	GL11.glDisable(GL11.GL_POLYGON_SMOOTH);
	GL11.glDisable(GL11.GL_BLEND);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glDepthMask(true);
	GL11.glDisable(GL11.GL_TEXTURE_2D);
	GL11.glEnable(GL11.GL_TEXTURE_1D);
	GL11.glBindTexture(GL11.GL_TEXTURE_1D, staticState.gradientTexture);
	GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
	GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
	GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);

	GL20.glUseProgram(0);

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

	return state;
}
 
Example 11
Source File: Test.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final static void initGL() {
	GL11.glEnable(GL11.GL_TEXTURE_2D);

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

	GLU.gluOrtho2D(0f, Display.getDisplayMode().getWidth(), 0f, Display.getDisplayMode().getHeight());
	GL11.glMatrixMode(GL11.GL_MODELVIEW);

	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
	GL11.glEnable(GL11.GL_BLEND);
}
 
Example 12
Source File: TextureMapRenderer.java    From VanillaFix with MIT License 5 votes vote down vote up
public static void popTextureMatrix() {
    int oldMatrixMode;
    oldMatrixMode = GlStateManager.glGetInteger(GL11.GL_MATRIX_MODE);
    GL11.glMatrixMode(GL11.GL_TEXTURE);
    GL11.glPopMatrix();
    GL11.glMatrixMode(oldMatrixMode);
}
 
Example 13
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 14
Source File: RenderUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static void gl11Cleanup() {
	GL11.glDisable(GL11.GL_LINE_SMOOTH);
	GL11.glPopMatrix();
	GL11.glMatrixMode(5888);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_BLEND);
}
 
Example 15
Source File: RenderUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static void gl11Cleanup() {
	GL11.glDisable(GL11.GL_LINE_SMOOTH);
	GL11.glPopMatrix();
	GL11.glMatrixMode(5888);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_BLEND);
}
 
Example 16
Source File: RenderUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static void gl11Setup() {
	GL11.glEnable(GL11.GL_BLEND);
       GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ZERO);
       GL11.glLineWidth(2.5F);
       GL11.glDisable(GL11.GL_TEXTURE_2D);
       GL11.glDisable(GL11.GL_DEPTH_TEST);
       GL11.glMatrixMode(5889);
	GL11.glEnable(GL11.GL_LINE_SMOOTH);
	GL11.glPushMatrix();
	offsetRender();
}
 
Example 17
Source File: RenderUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static void gl11Cleanup() {
	GL11.glPopMatrix();
	GL11.glMatrixMode(5888);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_BLEND);
}
 
Example 18
Source File: RenderUtils.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
public static void gl11Cleanup() {
	GL11.glDisable(GL11.GL_LINE_SMOOTH);
	GL11.glPopMatrix();
	GL11.glMatrixMode(5888);
	GL11.glEnable(GL11.GL_DEPTH_TEST);
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_BLEND);
}
 
Example 19
Source File: ModelViewer.java    From OpenRS with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	if (args.length < 1) {
		System.err.println("Usage: modelfile");
		System.exit(1);
	}

	ModelList list = new ModelList();
	try (Cache cache = new Cache(FileStore.open(Constants.CACHE_PATH))) {
		list.initialize(cache);
	}

	Model md = list.list(Integer.valueOf(args[0]));

	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;
	double near = 1; // near should be chosen as far into the scene as
						// possible
	double far = 1000;
	double fov = 1; // 1 gives you a 90� field of view. It's
					// tan(fov_angle)/2.
	GL11.glFrustum(-aspect * near * fov, aspect * near * fov, -fov, fov, near, far);

	GL11.glCullFace(GL11.GL_BACK);

	long last = 0;

	while (!Display.isCloseRequested()) {
		// Clear the screen and depth buffer
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

		GL11.glBegin(GL11.GL_TRIANGLES);

		for (int i = 0; i < md.faceCount; ++i) {
			int vertexA = md.triangleX[i];
			int vertexB = md.triangleY[i];
			int vertexC = md.triangleZ[i];

			int vertexAx = md.vertexX[vertexA];
			int vertexAy = md.vertexY[vertexA];
			int vertexAz = md.vertexZ[vertexA];

			int vertexBx = md.vertexX[vertexB];
			int vertexBy = md.vertexY[vertexB];
			int vertexBz = md.vertexZ[vertexB];

			int vertexCx = md.vertexX[vertexC];
			int vertexCy = md.vertexY[vertexC];
			int vertexCz = md.vertexZ[vertexC];

			short hsb = md.faceColor[i];

			int rgb = hsbToRGB(hsb);
			Color c = new Color(rgb);

			// convert to range of 0-1
			float rf = (float) c.getRed() / 255f;
			float gf = (float) c.getGreen() / 255f;
			float bf = (float) c.getBlue() / 255f;

			GL11.glColor3f(rf, gf, bf);

			GL11.glVertex3i(vertexAx, vertexAy, vertexAz - 50);
			GL11.glVertex3i(vertexBx, vertexBy, vertexBz - 50);
			GL11.glVertex3i(vertexCx, vertexCy, vertexCz - 50);
		}

		GL11.glEnd();

		Display.update();
		Display.sync(50); // fps

		long delta = System.currentTimeMillis() - last;
		last = System.currentTimeMillis();

		Camera.create();
		Camera.acceptInput(delta);

		Camera.apply();
	}

	Display.destroy();
}
 
Example 20
Source File: OffscreenRenderer.java    From tribaltrouble with GNU General Public License v2.0 4 votes vote down vote up
protected final void init() {
	Renderer.initGL();
	GL11.glViewport(0, 0, width, height);
	GL11.glMatrixMode(GL11.GL_MODELVIEW);
}