Skip to content

Commit

Permalink
Handle reshaping/resizing the Window, set SkyBox pos to camera pos
Browse files Browse the repository at this point in the history
  • Loading branch information
Seil0 committed Sep 24, 2020
1 parent 4b980bb commit e34786c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/rv/effects/EffectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void init(GL2 gl, Viewport screen, Configuration.Graphics config, Content
if (!success)
bloom = null;
//else
// viewer.addWindowResizeListener(bloom); // TODO
// viewer.addWindowResizeListener(bloom); // not needed windowResized is called in Renderer.reshape
}

if (config.useShadows) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/rv/ui/screens/ViewerScreenBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ public void selectionChanged(ISelectable newSelection)
}

if (trackerCameraType == TrackerCameraType.PLAYER && newSelection instanceof Agent) {
//viewer.getUI().getTrackerCamera().setTarget(newSelection); // TODO
CameraController.trackerCamera.setTarget(newSelection);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/rv/world/WorldModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import jsgl.jogl.light.LightModel;
import jsgl.math.vector.Matrix;
import jsgl.math.vector.Vec3f;
import org.magmaoffenburg.roboviz.rendering.CameraController;
import org.magmaoffenburg.roboviz.util.DataTypes;
import rv.Configuration;
import rv.comm.rcssserver.GameState;
Expand Down Expand Up @@ -232,7 +233,7 @@ private void initTeams()
sgItems.add(rightTeam);
}

public synchronized void update(GL gl, double elapsedMS) //, UserInterface ui) // TODO
public synchronized void update(GL gl, double elapsedMS)
{
// Allow scene graph items to update their states prior to rendering.
// This is done in the update loop rather than the scene graph update
Expand All @@ -243,7 +244,7 @@ public synchronized void update(GL gl, double elapsedMS) //, UserInterface ui) /
sgi.update(sceneGraph);
}

//skyBox.setPosition(ui.getCamera().getPosition()); // TODO
skyBox.setPosition(CameraController.camera.getPosition());

ballCircleTimeLeft -= elapsedMS / 1000.0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import rv.effects.EffectManager
import rv.ui.screens.LiveGameScreen
import rv.ui.screens.LogfileModeScreen
import rv.ui.screens.ViewerScreenBase
import rv.util.WindowResizeEvent
import rv.world.WorldModel
import rv.world.rendering.BasicSceneRenderer
import rv.world.rendering.PhongWorldRenderer
Expand All @@ -40,7 +41,7 @@ import java.io.File
/**
* TODO implement Window resizing
*/
class ViewRenderer : GLProgram(MainWindow.glCanvas.width, MainWindow.glCanvas.height) {
class ViewRenderer : GLProgram(MainWindow.instance.width, MainWindow.instance.height) {

private var isInitialized = false

Expand Down Expand Up @@ -160,24 +161,23 @@ class ViewRenderer : GLProgram(MainWindow.glCanvas.width, MainWindow.glCanvas.he
// Renderer.render()
synchronized(world) {
val gl2 = drawable.gl.gL2

if (graphics.useShadows) {
val shadowRenderer = effectManager.shadowRenderer
shadowRenderer.render(gl2, world, drawings)
}

if (graphics.useStereo) {
vantage?.applyLeft(gl2, glu, getScreen())
vantage?.applyLeft(gl2, glu, screen)
gl2?.glDrawBuffer(GL2.GL_BACK_LEFT)
gl2?.glClear(GL.GL_COLOR_BUFFER_BIT or GL.GL_DEPTH_BUFFER_BIT)
drawScene(gl2)

vantage?.applyRight(gl2, glu, getScreen())
vantage?.applyRight(gl2, glu, screen)
gl2.glDrawBuffer(GL2.GL_BACK_RIGHT)
gl2.glClear(GL.GL_COLOR_BUFFER_BIT or GL.GL_DEPTH_BUFFER_BIT)
drawScene(gl2)
} else {
vantage?.apply(gl2, glu, getScreen())
vantage?.apply(gl2, glu, screen)
gl2.glDrawBuffer(GL.GL_BACK)
gl2.glClear(GL.GL_COLOR_BUFFER_BIT or GL.GL_DEPTH_BUFFER_BIT)
drawScene(gl2)
Expand All @@ -189,17 +189,31 @@ class ViewRenderer : GLProgram(MainWindow.glCanvas.width, MainWindow.glCanvas.he
gl2.glDisable(GL2.GL_LIGHTING)
gl2.glMatrixMode(GL2.GL_PROJECTION)
gl2.glLoadIdentity()
glu.gluOrtho2D(0.0, getScreen().w.toDouble(), 0.0, getScreen().h.toDouble())
glu.gluOrtho2D(0.0, screen.w.toDouble(), 0.0, screen.h.toDouble())
gl2.glMatrixMode(GL2.GL_MODELVIEW)
gl2.glLoadIdentity()

activeScreen.render(gl2, glu, glut, getScreen())
activeScreen.render(gl2, glu, glut, screen)

gl2.glDisable(GL.GL_BLEND)
}

}

override fun reshape(drawable: GLAutoDrawable?, x: Int, y: Int, width: Int, height: Int) {
super.reshape(drawable, x, y, width, height)

if (graphics.useBloom || graphics.useShadows) {
sceneFBO?.dispose(drawable!!.gl)
msSceneFBO?.dispose(drawable!!.gl)
genFBO(drawable!!.gl.gL2, screen)
}

val event = WindowResizeEvent(this, screen)
activeScreen.windowResized(event)
effectManager.bloom.windowResized(event)
}

override fun addKeyListener(l: KeyListener?) {
AWTKeyAdapter(l, MainWindow.glCanvas).addTo(MainWindow.glCanvas)
}
Expand Down Expand Up @@ -228,7 +242,7 @@ class ViewRenderer : GLProgram(MainWindow.glCanvas.width, MainWindow.glCanvas.he

if (graphics.useBloom) {
numSamples = if (useFSAA) graphics.fsaaSamples else -1
genFBO(gl.gL2, getScreen()) // if we do post-processing we'll need an FBO for the scene
genFBO(gl.gL2, screen) // if we do post-processing we'll need an FBO for the scene
}

selectRenderer(gl.gL2, contentManager)
Expand Down Expand Up @@ -288,12 +302,12 @@ class ViewRenderer : GLProgram(MainWindow.glCanvas.width, MainWindow.glCanvas.he
gl.glColor4f(1f, 1f, 1f, 1f)

// render result to window
getScreen().apply(gl)
screen.apply(gl)
output.bind(gl)
EffectManager.renderScreenQuad(gl)
Texture2D.unbind(gl)
} else {
getScreen().apply(gl)
screen.apply(gl)
sceneRenderer?.render(gl, world, drawings)
}
}
Expand Down

0 comments on commit e34786c

Please sign in to comment.