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;
break;
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;
case HISTORY_BACK:
DisplayManager.INSTANCE.goBack();

View File

@ -2,6 +2,7 @@ package org.warp.picalculator.gui.graphicengine.gpu;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
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.Skin;
import com.jogamp.opengl.GL;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.util.texture.Texture;
public class GPUEngine implements GraphicEngine {
@ -27,6 +30,8 @@ public class GPUEngine implements GraphicEngine {
int[] size = new int[] { StaticVars.screenSize[0], StaticVars.screenSize[1] };
private final CopyOnWriteArrayList<BinaryFont> registeredFonts = new CopyOnWriteArrayList<BinaryFont>();
private Semaphore exitSemaphore = new Semaphore(0);
protected LinkedList<Texture> registeredTextures;
protected LinkedList<Texture> unregisteredTextures;
@Override
public int[] getSize() {
@ -68,6 +73,8 @@ public class GPUEngine implements GraphicEngine {
@Override
public void create(Runnable onInitialized) {
created = true;
registeredTextures = new LinkedList<>();
unregisteredTextures = new LinkedList<>();
r = new GPURenderer();
wnd = new NEWTWindow(this);
wnd.create();
@ -193,4 +200,8 @@ public class GPUEngine implements GraphicEngine {
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);
w = i.w;
h = i.h;
t.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
((GPUEngine)d).registerTexture(t);
initialized = true;
} catch (GLException | IOException e) {
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.GLPointerFunc;
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));
System.out.println("Loaded OpenGL");
// We may at this point tweak the caps and request a translucent drawable
caps.setHardwareAccelerated(true);
caps.setBackgroundOpaque(true); //transparency window
caps.setSampleBuffers(false);
// caps.setSampleBuffers(true);
// caps.setNumSamples(4);
final GLWindow glWindow = GLWindow.create(caps);
window = glWindow;
@ -301,6 +304,9 @@ class NEWTWindow implements GLEventListener {
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glShadeModel(GLLightingFunc.GL_FLAT);
//Multisampling
//gl.glEnable(GL.GL_MULTISAMPLE);
if (onInitialized != null) {
onInitialized.run();
onInitialized = null;
@ -332,7 +338,15 @@ class NEWTWindow implements GLEventListener {
private void onZoomChanged(GL2ES1 gl, boolean sizeChanged) {
float precWindowZoom = windowZoom;
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 height = realWindowSize[1];
@ -361,6 +375,17 @@ class NEWTWindow implements GLEventListener {
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_VERTEX_ARRAY);
gl.glEnableClientState(GLPointerFunc.GL_TEXTURE_COORD_ARRAY);

View File

@ -151,6 +151,7 @@ public class MathInputScreen extends Screen {
} else {
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);
}