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

The following examples show how to use org.lwjgl.opengl.GL11#glClearColor() . 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: 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 2
Source File: PBufferUniqueGraphics.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 3
Source File: FBOGraphics.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 4
Source File: BlurPane.java    From LWJGUI with MIT License 5 votes vote down vote up
private void blur(Context context) {
	// Bind final buffer
	this.buffer.bind();
	
	// Clear
	GL11.glClearColor(1, 1, 1, 1);
	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPTH_BUFFER_BIT);
	
	// Render the blur buffer (uses the buffer temp as texture)
	this.buffer.render(context);
	
	// unbind
	this.buffer.unbind();
}
 
Example 5
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 6
Source File: DesktopMini2DxGame.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
void createWindow(Lwjgl3Mini2DxWindow window, Lwjgl3ApplicationConfiguration config, long sharedContext) {
	long windowHandle = createGlfwWindow(config, sharedContext);
	window.create(windowHandle);
	window.setVisible(config.initialVisible);

	for (int i = 0; i < 2; i++) {
		GL11.glClearColor(config.initialBackgroundColor.r, config.initialBackgroundColor.g, config.initialBackgroundColor.b,
				config.initialBackgroundColor.a);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
		GLFW.glfwSwapBuffers(windowHandle);
	}
}
 
Example 7
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 8
Source File: OpenGLRenderer20.java    From ldparteditor with MIT License 4 votes vote down vote up
/**
 * Initializes the Scene and gives OpenGL-Hints
 */
@Override
public void init() {
    // MARK OpenGL Hints and Initialization
    GL11.glDepthMask(true);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    GL11.glEnable(GL11.GL_TEXTURE_2D);

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

    GL11.glDepthFunc(GL11.GL_LESS);

    GL11.glClearDepth(1.0f);
    GL11.glClearColor(View.background_Colour_r[0], View.background_Colour_g[0], View.background_Colour_b[0], 1.0f);

    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glPointSize(5);
    // GL11.glLineWidth(2);

    GL11.glEnable(GL11.GL_LIGHTING);
    GL11.glShadeModel(GL11.GL_SMOOTH);

    GL11.glEnable(GL11.GL_NORMALIZE);

    GL11.glEnable(GL11.GL_LIGHT0);
    GL11.glEnable(GL11.GL_LIGHT1);
    GL11.glEnable(GL11.GL_LIGHT2);
    GL11.glEnable(GL11.GL_LIGHT3);

    GL11.glLightModelfv(GL11.GL_LIGHT_MODEL_AMBIENT, BufferFactory.floatBuffer(new float[] { 0.1f, 0.1f, 0.1f, 1f }));

    GL11.glLightfv(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, BufferFactory.floatBuffer(new float[] { View.light1_Colour_r[0], View.light1_Colour_g[0], View.light1_Colour_b[0], 1f }));
    GL11.glLightfv(GL11.GL_LIGHT0, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { View.light1_specular_Colour_r[0], View.light1_specular_Colour_g[0], View.light1_specular_Colour_b[0], 1f }));
    GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_LINEAR_ATTENUATION, .001f);

    GL11.glLightfv(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, BufferFactory.floatBuffer(new float[] { View.light2_Colour_r[0], View.light2_Colour_g[0], View.light2_Colour_b[0], 1f }));
    GL11.glLightfv(GL11.GL_LIGHT1, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { View.light2_specular_Colour_r[0], View.light2_specular_Colour_g[0], View.light2_specular_Colour_b[0], 1f }));
    GL11.glLightf(GL11.GL_LIGHT1, GL11.GL_LINEAR_ATTENUATION, .001f);

    GL11.glLightfv(GL11.GL_LIGHT2, GL11.GL_DIFFUSE, BufferFactory.floatBuffer(new float[] { View.light3_Colour_r[0], View.light3_Colour_g[0], View.light3_Colour_b[0], 1f }));
    GL11.glLightfv(GL11.GL_LIGHT2, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { View.light3_specular_Colour_r[0], View.light3_specular_Colour_g[0], View.light3_specular_Colour_b[0], 1f }));
    GL11.glLightf(GL11.GL_LIGHT2, GL11.GL_LINEAR_ATTENUATION, .001f);

    GL11.glLightfv(GL11.GL_LIGHT3, GL11.GL_DIFFUSE, BufferFactory.floatBuffer(new float[] { View.light4_Colour_r[0], View.light4_Colour_g[0], View.light4_Colour_b[0], 1f }));
    GL11.glLightfv(GL11.GL_LIGHT3, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { View.light4_specular_Colour_r[0], View.light4_specular_Colour_g[0], View.light4_specular_Colour_b[0], 1f }));
    GL11.glLightf(GL11.GL_LIGHT3, GL11.GL_LINEAR_ATTENUATION, .001f);

    GL11.glEnable(GL11.GL_COLOR_MATERIAL);
    GL11.glColorMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE);

    GL11.glMaterialfv(GL11.GL_FRONT, GL11.GL_SPECULAR, BufferFactory.floatBuffer(new float[] { 1.0f, 1.0f, 1.0f, 1.0f }));
    GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, 128f);


    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);

    if (fsGlossId == -1) {
        vsGlossId = loadGlossVertexShader();
        fsGlossId = loadGlossFragmentShader();
        if (pGlossId == -1 && vsGlossId != -1 && fsGlossId != -1) {
            pGlossId = GL20.glCreateProgram();
            GL20.glAttachShader(pGlossId, vsGlossId);
            GL20.glAttachShader(pGlossId, fsGlossId);
            GL20.glLinkProgram(pGlossId);
            GL20.glValidateProgram(pGlossId);
            baseImageLoc = GL20.glGetUniformLocation(pGlossId, "colorMap"); //$NON-NLS-1$
            glossMapLoc = GL20.glGetUniformLocation(pGlossId, "glossMap"); //$NON-NLS-1$
            cubeMapLoc = GL20.glGetUniformLocation(pGlossId, "cubeMap"); //$NON-NLS-1$
            cubeMapMatteLoc = GL20.glGetUniformLocation(pGlossId, "cubeMapMatte"); //$NON-NLS-1$
            cubeMapMetalLoc = GL20.glGetUniformLocation(pGlossId, "cubeMapMetal"); //$NON-NLS-1$
            alphaSwitchLoc = GL20.glGetUniformLocation(pGlossId, "alphaSwitch"); //$NON-NLS-1$
            normalSwitchLoc = GL20.glGetUniformLocation(pGlossId, "normalSwitch"); //$NON-NLS-1$
            noTextureSwitch = GL20.glGetUniformLocation(pGlossId, "noTextureSwitch"); //$NON-NLS-1$
            noGlossMapSwitch = GL20.glGetUniformLocation(pGlossId, "noGlossMapSwitch"); //$NON-NLS-1$
            cubeMapSwitch = GL20.glGetUniformLocation(pGlossId, "cubeMapSwitch"); //$NON-NLS-1$
            noLightSwitch = GL20.glGetUniformLocation(pGlossId, "noLightSwitch"); //$NON-NLS-1$
        }
    }
}
 
Example 9
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draw a curve to the screen that's tinted with `color`. The first time
 * this is called this caches the image result of the curve and on subsequent
 * runs it just draws the cached copy to the screen.
 * @param color tint of the curve
 * @param borderColor the curve border color
 * @param from index to draw from
 * @param to index to draw to (exclusive)
 */
public void draw(Color color, Color borderColor, int from, int to) {
	float alpha = color.a;

	if (fbo == null)
		initFBO();

	if (lastPointDrawn != to || firstPointDrawn != from) {
		int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
		int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
		//glGetInteger requires a buffer of size 16, even though just 4
		//values are returned in this specific case
		IntBuffer oldViewport = BufferUtils.createIntBuffer(16);
		GL11.glGetInteger(GL11.GL_VIEWPORT, oldViewport);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.getID());
		GL11.glViewport(0, 0, fbo.width, fbo.height);
		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
		this.renderCurve(color, borderColor, from, to, firstPointDrawn != from);
		lastPointDrawn = to;
		firstPointDrawn = from;
		color.a = 1f;

		GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb);
		GL11.glViewport(oldViewport.get(0), oldViewport.get(1), oldViewport.get(2), oldViewport.get(3));
	}

	// draw a fullscreen quad with the texture that contains the curve
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_TEXTURE_1D);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.getTextureID());
	GL11.glBegin(GL11.GL_QUADS);
	GL11.glColor4f(1.0f, 1.0f, 1.0f, alpha);
	GL11.glTexCoord2f(1.0f, 1.0f);
	GL11.glVertex2i(fbo.width, 0);
	GL11.glTexCoord2f(0.0f, 1.0f);
	GL11.glVertex2i(0, 0);
	GL11.glTexCoord2f(0.0f, 0.0f);
	GL11.glVertex2i(0, fbo.height);
	GL11.glTexCoord2f(1.0f, 0.0f);
	GL11.glVertex2i(fbo.width, fbo.height);
	GL11.glEnd();
}
 
Example 10
Source File: Snippet195.java    From ldparteditor with MIT License 4 votes vote down vote up
public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    //        try {
    //            GLContext.useContext(canvas);
    //        } catch (LWJGLException e) {
    //            e.printStackTrace();
    //        }

    canvas.addListener(SWT.Resize, event -> {
        Rectangle bounds = canvas.getBounds();
        float fAspect = (float) bounds.width / (float) bounds.height;
        canvas.setCurrent();
        //                try {
        //                    GLContext.useContext(canvas);
        //                } catch (LWJGLException e) {
        //                    e.printStackTrace();
        //                }
        GL11.glViewport(0, 0, bounds.width, bounds.height);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
        GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();
    });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    shell.setText("SWT/LWJGL Example"); //$NON-NLS-1$
    shell.setSize(640, 480);
    shell.open();

    display.asyncExec(new Runnable() {
        int rot = 0;

        @Override
        public void run() {
            if (!canvas.isDisposed()) {
                canvas.setCurrent();
                //                    try {
                //                        GLContext.useContext(canvas);
                //                    } catch (LWJGLException e) {
                //                        e.printStackTrace();
                //                    }
                GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
                GL11.glLoadIdentity();
                GL11.glTranslatef(0.0f, 0.0f, -10.0f);
                float frot = rot;
                GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
                GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
                rot++;
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
                GL11.glColor3f(0.9f, 0.9f, 0.9f);
                drawTorus(1, 1.9f + (float) Math.sin(0.004f * frot), 15, 15);
                GL11.glColor3f(0.9f, 0.9f, 0f);
                drawTorus(1.9f, 5.9f + (float) Math.sin(0.004f * frot), 15, 15);
                canvas.swapBuffers();
                display.asyncExec(this);
            }
        }
    });

    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
 
Example 11
Source File: vboWithIndices.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void init() {
    
    Matrix4f.setIdentity(viewport);
    shaderProgram = new GLShader("primitive.vert", "primitive.frag"); //$NON-NLS-1$ //$NON-NLS-2$
    shaderProgram.use();
    
    GL11.glClearDepth(1.0f);
    GL11.glClearColor(View.primitive_background_Colour_r[0], View.primitive_background_Colour_g[0], View.primitive_background_Colour_b[0], 1.0f);
    
    new Thread(new Runnable() {
        
        @Override
        public void run() {

            while (isRendering.get()) {
                
                final float zoom = cp.getZoom();
                final Matrix4f viewport_translation = cp.getTranslation();
                final float STEP = 22f * zoom * View.PIXEL_PER_LDU;
                cp.setRotationWidth(STEP);
                
                Matrix4f viewport_transform = new Matrix4f();
                Matrix4f.setIdentity(viewport_transform);
                Matrix4f.scale(new Vector3f(zoom, zoom, zoom), viewport_transform, viewport_transform);
                Matrix4f.mul(viewport_transform, viewport_translation, viewport_transform);
                cp.setViewport(viewport_transform);
                viewport = viewport_transform;
                
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }).start();
    
    
    // Set up vertex data (and buffer(s)) and attribute pointers
    float[] vertices = new float[]{
         0.5f,  0.5f, 0.0f,  // Top Right
         0.5f, -0.5f, 0.0f,  // Bottom Right
        -0.5f, -0.5f, 0.0f,  // Bottom Left
        -0.5f,  0.5f, 0.0f   // Top Left 
    };
    int[] indices = new int[]{  // Note that we start from 0!
        0, 1, 3,  // First Triangle
        1, 2, 3   // Second Triangle
    };
    
    VAO = GL30.glGenVertexArrays();
    VBO = GL15.glGenBuffers();
    EBO = GL15.glGenBuffers();
    // Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s).
    GL30.glBindVertexArray(VAO);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);

    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, EBO);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indices, GL15.GL_STATIC_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, 3 * 4, 0);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Note that this is allowed, the call to glVertexAttribPointer registered VBO as the currently bound vertex buffer object so afterwards we can safely unbind

    GL30.glBindVertexArray(0); // Unbind VAO (it's always a good thing to unbind any buffer/array to prevent strange bugs), remember: do NOT unbind the EBO, keep it bound to this VAO

}
 
Example 12
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#glClearColor(float, float, float, float)
 */
public void glClearColor(float red, float green, float blue, float alpha) {
	GL11.glClearColor(red, green, blue, alpha);
}
 
Example 13
Source File: RenderUtils.java    From LookingGlass with GNU General Public License v3.0 4 votes vote down vote up
@SideOnly(Side.CLIENT)
public final static void renderWorldToTexture(float renderTime, int framebuffer, int width, int height) {
	if (framebuffer == 0) return;
	Minecraft mc = Minecraft.getMinecraft();
	if (mc.skipRenderWorld) return;
	EntityRenderer entityRenderer = mc.entityRenderer;

	//Backup current render settings
	int heightBackup = mc.displayHeight;
	int widthBackup = mc.displayWidth;

	int thirdPersonBackup = mc.gameSettings.thirdPersonView;
	boolean hideGuiBackup = mc.gameSettings.hideGUI;
	int particleBackup = mc.gameSettings.particleSetting;
	boolean anaglyphBackup = mc.gameSettings.anaglyph;
	int renderDistanceBackup = mc.gameSettings.renderDistanceChunks;
	float FOVbackup = mc.gameSettings.fovSetting;

	//Render world
	try {
		//Set all of the render setting to work on the proxy world
		mc.displayHeight = height;
		mc.displayWidth = width;

		//TODO: params (FOV, Particle setting, renderDistance)
		mc.gameSettings.thirdPersonView = 0;
		mc.gameSettings.hideGUI = true;
		//mc.gameSettings.particleSetting = ;
		mc.gameSettings.anaglyph = false;
		//mc.gameSettings.renderDistanceChunks = ;  
		//mc.gameSettings.fovSetting = ;

		//Set gl options
		GL11.glViewport(0, 0, mc.displayWidth, mc.displayHeight);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebuffer);
		GL11.glClearColor(1.0f, 0.0f, 0.0f, 0.5f);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

		int i1 = mc.gameSettings.limitFramerate;
		if (mc.isFramerateLimitBelowMax()) {
			entityRenderer.renderWorld(renderTime, (1000000000 / i1));
		} else {
			entityRenderer.renderWorld(renderTime, 0L);
		}
	} catch (Exception e) {
		try {
			//Clean up the tessellator, just in case.
			Tessellator.instance.draw();
		} catch (Exception e2) {
			//It might throw an exception, but that just means we didn't need to clean it up (this time)
		}
		throw new RuntimeException("Error while rendering proxy world", e);
	} finally {
		GL11.glEnable(GL11.GL_TEXTURE_2D);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, 0);

		GL11.glViewport(0, 0, widthBackup, heightBackup);
		GL11.glLoadIdentity();

		mc.gameSettings.thirdPersonView = thirdPersonBackup;
		mc.gameSettings.hideGUI = hideGuiBackup;
		mc.gameSettings.particleSetting = particleBackup;
		mc.gameSettings.anaglyph = anaglyphBackup;
		mc.gameSettings.renderDistanceChunks = renderDistanceBackup;
		mc.gameSettings.fovSetting = FOVbackup;

		mc.displayHeight = heightBackup;
		mc.displayWidth = widthBackup;
	}
}
 
Example 14
Source File: LwjglRasteriser.java    From tectonicus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void clear(Color clearColour)
{
	GL11.glClearColor(clearColour.getRed()/255.0f, clearColour.getGreen()/255.0f, clearColour.getBlue()/255.0f, 0);
	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
}
 
Example 15
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 16
Source File: CurveRenderState.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draw a curve to the screen that's tinted with `color`. The first time
 * this is called this caches the image result of the curve and on subsequent
 * runs it just draws the cached copy to the screen.
 * @param color tint of the curve
 * @param borderColor the curve border color
 * @param from index to draw from
 * @param to index to draw to (exclusive)
 */
public void draw(Color color, Color borderColor, int from, int to) {
	float alpha = color.a;

	if (fbo == null) {
		// this should not be null, but issue #106 claims it is possible, at least 3 people had this...
		// debugging shows that the draw was called after discardGeometry was, which does not really make sense
		initFBO();
	}

	if (lastPointDrawn != to || firstPointDrawn != from) {
		int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
		int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
		//glGetInteger requires a buffer of size 16, even though just 4
		//values are returned in this specific case
		IntBuffer oldViewport = BufferUtils.createIntBuffer(16);
		GL11.glGetInteger(GL11.GL_VIEWPORT, oldViewport);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.getID());
		GL11.glViewport(0, 0, fbo.width, fbo.height);
		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
		this.renderCurve(color, borderColor, from, to, firstPointDrawn != from);
		lastPointDrawn = to;
		firstPointDrawn = from;
		color.a = 1f;

		GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex);
		EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb);
		GL11.glViewport(oldViewport.get(0), oldViewport.get(1), oldViewport.get(2), oldViewport.get(3));
	}

	// draw a fullscreen quad with the texture that contains the curve
	GL11.glEnable(GL11.GL_TEXTURE_2D);
	GL11.glDisable(GL11.GL_TEXTURE_1D);
	GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.getTextureID());
	GL11.glBegin(GL11.GL_QUADS);
	GL11.glColor4f(1.0f, 1.0f, 1.0f, alpha);
	GL11.glTexCoord2f(1.0f, 1.0f);
	GL11.glVertex2i(fbo.width, 0);
	GL11.glTexCoord2f(0.0f, 1.0f);
	GL11.glVertex2i(0, 0);
	GL11.glTexCoord2f(0.0f, 0.0f);
	GL11.glVertex2i(0, fbo.height);
	GL11.glTexCoord2f(1.0f, 0.0f);
	GL11.glVertex2i(fbo.width, fbo.height);
	GL11.glEnd();
}
 
Example 17
Source File: MasterRenderer.java    From OpenGL-Animation with The Unlicense 4 votes vote down vote up
/**
 * Prepare to render the current frame by clearing the framebuffer.
 */
private void prepare() {
	GL11.glClearColor(1, 1, 1, 1);
	GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | 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);
}