From 2d7d9f3a01827b2560f2b2c38b9ae72ed0dbae99 Mon Sep 17 00:00:00 2001 From: Bart van Blokland Date: Wed, 21 May 2014 10:46:22 +0200 Subject: [PATCH] Reduced openGL requirement level from 3.0 to 1.1 --- Python-Powered-Pixels/src/core/Main.java | 21 ---- .../src/graphics/TextureRenderer.java | 100 ------------------ .../src/texture/Texture.java | 1 - 3 files changed, 122 deletions(-) delete mode 100644 Python-Powered-Pixels/src/graphics/TextureRenderer.java diff --git a/Python-Powered-Pixels/src/core/Main.java b/Python-Powered-Pixels/src/core/Main.java index 44fa08e..4a6020b 100644 --- a/Python-Powered-Pixels/src/core/Main.java +++ b/Python-Powered-Pixels/src/core/Main.java @@ -4,9 +4,6 @@ import static org.lwjgl.util.glu.GLU.gluOrtho2D; import java.io.File; -import java.io.FileInputStream; - -import graphics.TextureRenderer; import javax.swing.JOptionPane; @@ -31,9 +28,7 @@ public static void main(String[] args) { interpreter.execfile(Main.class.getClassLoader().getResourceAsStream("init.py")); PySystemState sys = Py.getSystemState(); sys.path.append(new PyString(getJARPath())); - TextureRenderer.init(); interpreter.execfile("script.py"); - idle(); } catch(Exception e) { JOptionPane.showMessageDialog(null, e.toString(), "Python error", JOptionPane.ERROR_MESSAGE); } @@ -70,14 +65,9 @@ private static void initOpenGL() { } private static void newFrame() { - TextureRenderer.drawScreenFrame(); - Display.update(); Display.sync(60); - TextureRenderer.setupNextFrame(); - TextureRenderer.updateTexture(); - if(Display.isCloseRequested()) { Display.destroy(); System.exit(0); @@ -98,17 +88,6 @@ public static void newBlankFrame() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } - private static void idle() { - System.out.println("Idling.."); - while(!Display.isCloseRequested()) { - TextureRenderer.drawScreenFrame(); - TextureRenderer.setupNextFrame(); - - Display.update(); - Display.sync(60); - } - } - private static String getJARPath() { String path = Main.class.getProtectionDomain().getCodeSource().getLocation().getPath(); File jarFile = new File(path).getParentFile(); diff --git a/Python-Powered-Pixels/src/graphics/TextureRenderer.java b/Python-Powered-Pixels/src/graphics/TextureRenderer.java deleted file mode 100644 index 2b8c804..0000000 --- a/Python-Powered-Pixels/src/graphics/TextureRenderer.java +++ /dev/null @@ -1,100 +0,0 @@ -package graphics; - -import static org.lwjgl.opengl.GL30.*; -import static org.lwjgl.opengl.GL11.*; -import static org.lwjgl.util.glu.GLU.gluOrtho2D; - -import java.nio.ByteBuffer; - -import org.lwjgl.opengl.Display; - - -public class TextureRenderer { - private static int frameBufferID = -1; - private static int renderTextureID = -1; - private static int previousWidth = 640; - private static int previousHeight = 480; - - public static void init() { - frameBufferID = glGenFramebuffers(); - glBindFramebuffer(GL_FRAMEBUFFER, frameBufferID); - createRenderTexture(); - linkRenderTexture(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - } - - public static void drawScreenFrame() { - int width = Display.getWidth(); - int height = Display.getHeight(); - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - glViewport(0, 0, width, height); - gluOrtho2D(0, 1, 0, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glEnable(GL_TEXTURE_2D); - glColor4f(1, 1, 1, 1); - glBindTexture(GL_TEXTURE_2D, renderTextureID); - - glBegin(GL_QUADS); - glTexCoord2d(0, 0); - glVertex2d(-1, -1); - glTexCoord2d(1, 0); - glVertex2d(1, -1); - glTexCoord2d(1, 1); - glVertex2d(1, 1); - glTexCoord2d(0, 1); - glVertex2d(-1, 1); - glEnd(); - } - - public static void setupNextFrame() { - glDisable(GL_TEXTURE_2D); - glBindFramebuffer(GL_FRAMEBUFFER, frameBufferID); - } - - public static void updateTexture() { - int width = Display.getWidth(); - int height = Display.getHeight(); - - if((width != previousWidth) || (height != previousHeight)) { - createRenderTexture(); - linkRenderTexture(); - } - - previousWidth = width; - previousHeight = height; - } - - private static void createRenderTexture() { - glEnable(GL_TEXTURE_2D); - - if(renderTextureID != -1) { - glDeleteTextures(renderTextureID); - } - - renderTextureID = glGenTextures(); - glBindTexture(GL_TEXTURE_2D, renderTextureID); - - int width = Display.getWidth(); - int height = Display.getHeight(); - - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (ByteBuffer)null); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - glDisable(GL_TEXTURE_2D); - } - - private static void linkRenderTexture() { - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderTextureID, 0); - - int isFramebufferOperational = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if(isFramebufferOperational != GL_FRAMEBUFFER_COMPLETE) { - System.out.println("ERROR: FrameBuffer is not operational!"); - } - } -} diff --git a/Python-Powered-Pixels/src/texture/Texture.java b/Python-Powered-Pixels/src/texture/Texture.java index 20aabdf..42bb8c5 100644 --- a/Python-Powered-Pixels/src/texture/Texture.java +++ b/Python-Powered-Pixels/src/texture/Texture.java @@ -2,7 +2,6 @@ import static org.lwjgl.opengl.GL11.*; import graphics.Colour; -import graphics.GraphicsController; public class Texture { private final int id;