Fixed a bug

This commit is contained in:
Andrea Cavalli 2018-03-31 18:42:21 +02:00
parent 6e7631eb08
commit b788bedc48
5 changed files with 43 additions and 5 deletions

View File

@ -604,7 +604,8 @@ public class Keyboard {
refresh = true; refresh = true;
break; break;
case ZOOM_MODE: case ZOOM_MODE:
StaticVars.windowZoom = ((StaticVars.windowZoom - 0.5f) % 2f) + 1f; StaticVars.windowZoom = ((StaticVars.windowZoom - 1) % 2) + 2;
// StaticVars.windowZoom = ((StaticVars.windowZoom - 0.5f) % 2f) + 1f;
refresh = true; refresh = true;
case HISTORY_BACK: case HISTORY_BACK:
DisplayManager.INSTANCE.goBack(); DisplayManager.INSTANCE.goBack();

View File

@ -2,6 +2,7 @@ package org.warp.picalculator.gui.graphicengine.gpu;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -14,7 +15,9 @@ import org.warp.picalculator.gui.graphicengine.GraphicEngine;
import org.warp.picalculator.gui.graphicengine.RenderingLoop; import org.warp.picalculator.gui.graphicengine.RenderingLoop;
import org.warp.picalculator.gui.graphicengine.Skin; import org.warp.picalculator.gui.graphicengine.Skin;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLProfile; import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.util.texture.Texture;
public class GPUEngine implements GraphicEngine { public class GPUEngine implements GraphicEngine {
@ -27,6 +30,8 @@ public class GPUEngine implements GraphicEngine {
int[] size = new int[] { StaticVars.screenSize[0], StaticVars.screenSize[1] }; int[] size = new int[] { StaticVars.screenSize[0], StaticVars.screenSize[1] };
private final CopyOnWriteArrayList<BinaryFont> registeredFonts = new CopyOnWriteArrayList<BinaryFont>(); private final CopyOnWriteArrayList<BinaryFont> registeredFonts = new CopyOnWriteArrayList<BinaryFont>();
private Semaphore exitSemaphore = new Semaphore(0); private Semaphore exitSemaphore = new Semaphore(0);
protected LinkedList<Texture> registeredTextures;
protected LinkedList<Texture> unregisteredTextures;
@Override @Override
public int[] getSize() { public int[] getSize() {
@ -68,6 +73,8 @@ public class GPUEngine implements GraphicEngine {
@Override @Override
public void create(Runnable onInitialized) { public void create(Runnable onInitialized) {
created = true; created = true;
registeredTextures = new LinkedList<>();
unregisteredTextures = new LinkedList<>();
r = new GPURenderer(); r = new GPURenderer();
wnd = new NEWTWindow(this); wnd = new NEWTWindow(this);
wnd.create(); wnd.create();
@ -193,4 +200,8 @@ public class GPUEngine implements GraphicEngine {
return registeredFonts; return registeredFonts;
} }
public void registerTexture(Texture t) {
unregisteredTextures.addLast(t);
}
} }

View File

@ -45,7 +45,7 @@ public class GPUSkin implements Skin {
t = GPURenderer.importTexture(i.f, i.deleteOnExit); t = GPURenderer.importTexture(i.f, i.deleteOnExit);
w = i.w; w = i.w;
h = i.h; h = i.h;
t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); ((GPUEngine)d).registerTexture(t);
initialized = true; initialized = true;
} catch (GLException | IOException e) { } catch (GLException | IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -53,6 +53,7 @@ import com.jogamp.opengl.fixedfunc.GLLightingFunc;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc; import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.fixedfunc.GLPointerFunc; import com.jogamp.opengl.fixedfunc.GLPointerFunc;
import com.jogamp.opengl.util.Animator; import com.jogamp.opengl.util.Animator;
import com.jogamp.opengl.util.texture.Texture;
/** /**
* *
@ -89,8 +90,10 @@ class NEWTWindow implements GLEventListener {
final GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2ES1)); final GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2ES1));
System.out.println("Loaded OpenGL"); System.out.println("Loaded OpenGL");
// We may at this point tweak the caps and request a translucent drawable // We may at this point tweak the caps and request a translucent drawable
caps.setHardwareAccelerated(true);
caps.setBackgroundOpaque(true); //transparency window caps.setBackgroundOpaque(true); //transparency window
caps.setSampleBuffers(false); // caps.setSampleBuffers(true);
// caps.setNumSamples(4);
final GLWindow glWindow = GLWindow.create(caps); final GLWindow glWindow = GLWindow.create(caps);
window = glWindow; window = glWindow;
@ -292,7 +295,7 @@ class NEWTWindow implements GLEventListener {
//Vsync //Vsync
gl.setSwapInterval(1); gl.setSwapInterval(1);
//Textures //Textures
gl.glEnable(GL.GL_TEXTURE_2D); gl.glEnable(GL.GL_TEXTURE_2D);
@ -301,6 +304,9 @@ class NEWTWindow implements GLEventListener {
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glShadeModel(GLLightingFunc.GL_FLAT); gl.glShadeModel(GLLightingFunc.GL_FLAT);
//Multisampling
//gl.glEnable(GL.GL_MULTISAMPLE);
if (onInitialized != null) { if (onInitialized != null) {
onInitialized.run(); onInitialized.run();
onInitialized = null; onInitialized = null;
@ -332,7 +338,15 @@ class NEWTWindow implements GLEventListener {
private void onZoomChanged(GL2ES1 gl, boolean sizeChanged) { private void onZoomChanged(GL2ES1 gl, boolean sizeChanged) {
float precWindowZoom = windowZoom; float precWindowZoom = windowZoom;
windowZoom = StaticVars.getCurrentZoomValue(); windowZoom = StaticVars.getCurrentZoomValue();
System.out.println("sizechange" + windowZoom);
if (((precWindowZoom % ((int)precWindowZoom)) != 0f) != ((windowZoom % ((int)windowZoom)) != 0f)) {
boolean linear = (windowZoom % ((int)windowZoom)) != 0f;
for(Texture t : disp.registeredTextures) {
t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, linear ? GL.GL_LINEAR : GL.GL_NEAREST);
t.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
}
}
final int width = realWindowSize[0]; final int width = realWindowSize[0];
final int height = realWindowSize[1]; final int height = realWindowSize[1];
@ -360,6 +374,17 @@ class NEWTWindow implements GLEventListener {
if (windowZoom != StaticVars.getCurrentZoomValue()) { if (windowZoom != StaticVars.getCurrentZoomValue()) {
onZoomChanged(gl, false); onZoomChanged(gl, false);
} }
Boolean linear = null;
while(!disp.unregisteredTextures.isEmpty()) {
if (linear == null) {
linear = (windowZoom % ((int)windowZoom)) != 0f;
}
Texture t = disp.unregisteredTextures.pop();
t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
t.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
disp.registeredTextures.addLast(t);
}
gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY); gl.glEnableClientState(GLPointerFunc.GL_COLOR_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY); gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY);

View File

@ -151,6 +151,7 @@ public class MathInputScreen extends Screen {
} else { } else {
skinN = 21; skinN = 21;
} }
DisplayManager.INSTANCE.guiSkin.use(DisplayManager.INSTANCE.engine);
renderer.glFillRect(2 + 18 * pos + 2 * spacersNumb, 2, 16, 16, 16 * skinN, 16 * 0, 16, 16); renderer.glFillRect(2 + 18 * pos + 2 * spacersNumb, 2, 16, 16, 16 * skinN, 16 * 0, 16, 16);
} }