<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>115</bug_id>
          
          <creation_ts>2004-10-22 04:48:03 +0200</creation_ts>
          <short_desc>GLDrawable.swapBuffers(); behaviour</short_desc>
          <delta_ts>2010-03-24 07:47:00 +0100</delta_ts>
          <reporter_accessible>0</reporter_accessible>
          <cclist_accessible>0</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Jogl</product>
          <component>core</component>
          <version>1</version>
          <rep_platform>All</rep_platform>
          <op_sys>windows</op_sys>
          <bug_status>VERIFIED</bug_status>
          <resolution>WORKSFORME</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P1</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Sven Gothel">sgothel</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          
          
          <cf_type>DEFECT</cf_type>
          <cf_scm_refs></cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>131</commentid>
    <comment_count>0</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2010-03-24 07:47:00 +0100</bug_when>
    <thetext>


---- Reported by skippy 2004-10-22 04:48:03 ----

windowed + automatic-swap = only dark-green box (as expected) 
fullscreen + automatic-swap = only dark-green box (as expected) 
 
forced-swap + canvas.setAutoSwapBufferMode(true); combo 
   (which is wrong, but shows the unpredicted behaviour) 
windowed + forced-swap = dark/bright green boxes flicking (hm...) 
fullscreen + forced-swap = only dark-green box (hm...) 
^^^^^^^^^^ both should result in the same gfx, but are different. 
 
What happens: 
in fullscreen-mode the swapBuffers() is ignored (correct) 
in windowed-mode the swapBuffer() is processed (wrong, as: canvas.
setAutoSwapBufferMode(true)) 
 
forced-swap + canvas.setAutoSwapBufferMode(false); combo works just fine.

import java.awt.*; 
import java.awt.event.*; 
import javax.swing.JOptionPane; 
import javax.swing.UIManager; 
 
import net.java.games.jogl.*; 
 
public class Run 
{ 
   public static void main(String[] args) throws Exception 
   { 
      new Run(); 
   } 
 
 
 
   private Run() 
   { 
      try 
      { 
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
      } 
      catch (Exception exc) 
      { 
         // 
      } 
 
      // Settings 
 
      final boolean fullscreen = JOptionPane.OK_OPTION == JOptionPane.
showConfirmDialog(new Frame(), &quot;Do you want to enter fullscreen-mode?&quot;, 
&quot;Fullscreen?&quot;, JOptionPane.YES_NO_OPTION); 
 
      try 
      { 
         Thread.sleep(500); 
      } 
      catch (Exception exc) 
      { 
         // 
      } 
 
      final boolean forcedSwap = JOptionPane.OK_OPTION == JOptionPane.
showConfirmDialog(new Frame(), &quot;Do you want to forcibly swap buffers?&quot;, 
&quot;ForcedSwap?&quot;, JOptionPane.YES_NO_OPTION); 
 
      // GUI 
 
      final GLCapabilities caps = new GLCapabilities(); 
      caps.setHardwareAccelerated(true); 
 
      final GLCanvas canvas = GLDrawableFactory.getFactory().
createGLCanvas(caps); 
 
      /* 
       * If this mode is set to true, whatever the &quot;forcedSwap&quot; value might be, 
       * behaviour changes in fullscreen/windowed-mode. 
       */ 
      canvas.setAutoSwapBufferMode(true); 
      // Should be: [!forcedSwap] in perfect code 
 
      canvas.setNoAutoRedrawMode(true); 
      canvas.addGLEventListener(new Renderer(forcedSwap)); 
      canvas.addKeyListener(new KeyboardShutdown()); 
 
      final Frame frame = new Frame(); 
      frame.setTitle(&quot;Bouncing box&quot;); 
      frame.setResizable(false); 
      frame.add(canvas, BorderLayout.CENTER); 
 
      if (fullscreen) 
      { 
         frame.setUndecorated(true); 
 
         GraphicsEnvironment env = GraphicsEnvironment.
getLocalGraphicsEnvironment(); 
         GraphicsDevice device = env.getDefaultScreenDevice(); 
         device.setFullScreenWindow(frame); 
      } 
      else 
      { 
         frame.setSize(640, 480); 
         frame.setLocationRelativeTo(null); 
         frame.setVisible(true); 
      } 
 
      frame.addWindowListener(new FrameShutdown()); 
 
      canvas.requestFocus(); 
 
      running = true; 
      n00bL00p(frame, canvas); 
   } 
 
   /** 
    * LOOP 
    */ 
 
   private boolean running; 
 
 
 
   private void n00bL00p(Frame frame, GLCanvas canvas) 
   { 
      while (running) 
      { 
         logic(); 
         canvas.display(); 
      } 
 
      // Close 
      frame.setVisible(false); 
      frame.dispose(); 
      System.exit(0); 
   } 
 
   /** 
    * LOGIC 
    */ 
 
   private int w, h; 
 
   private int rectX, rectY, rectR, rectSpeedX, rectSpeedY; 
 
 
 
   private void logic() 
   { 
      rectX += rectSpeedX; 
      rectY += rectSpeedY; 
 
      if (rectX &lt; 0 || rectX &gt; w) 
      { 
         rectSpeedX *= -1; 
      } 
 
      if (rectY &lt; 0 || rectY &gt; h) 
      { 
         rectSpeedY *= -1; 
      } 
   } 
 
   /** 
    * RENDERER 
    */ 
 
   private class Renderer implements GLEventListener 
   { 
      private final boolean forcedSwap; 
 
 
 
      public Renderer(boolean forcedSwap) 
      { 
         this.forcedSwap = forcedSwap; 
      } 
 
 
 
      public void init(GLDrawable d) 
      { 
         GL gl = d.getGL(); 
         gl.glShadeModel(GL.GL_SMOOTH); 
         gl.glClearColor(0.0F, 0.0F, 0.0F, 1.0F); 
 
         rectR = 32; 
         rectSpeedX = 4; 
         rectSpeedY = 4; 
      } 
 
 
 
      public void display(GLDrawable d) 
      { 
         GL gl = d.getGL(); 
 
         // Bright green box 
         this.renderBox(gl, rectX - rectR, rectY, rectR, new float[] { 0.0F, 1.
0F, 0.0F }); 
 
         if (forcedSwap) 
         { 
            // Swap in-between 
            d.swapBuffers(); 
         } 
 
         // Dark green box 
         this.renderBox(gl, rectX + rectR, rectY, rectR, new float[] { 0.0F, 0.
5F, 0.0F }); 
 
         if (forcedSwap) 
         { 
            // Swap finally 
            d.swapBuffers(); 
         } 
      } 
 
 
 
      private void renderBox(GL gl, int x, int y, int r, float[] color) 
      { 
         gl.glClear(GL.GL_COLOR_BUFFER_BIT); 
 
         this.enable2D(gl); 
 
         gl.glColor3fv(color); 
         gl.glBegin(GL.GL_QUADS); 
         gl.glVertex2f(x - r, y - r); 
         gl.glVertex2f(x + r, y - r); 
         gl.glVertex2f(x + r, y + r); 
         gl.glVertex2f(x - r, y + r); 
         gl.glEnd(); 
 
         this.disable2D(gl); 
 
         try 
         { 
            Thread.sleep(10L); 
         } 
         catch (Exception exc) 
         { 
            // Terrible I know, just for testing. 
         } 
      } 
 
 
 
      public void displayChanged(GLDrawable arg0, boolean arg1, boolean arg2) 
      { 
         // 
      } 
 
 
 
      public void reshape(GLDrawable arg0, int arg1, int arg2, int arg3, int 
arg4) 
      { 
         w = arg3; 
         h = arg4; 
      } 
 
 
 
      private final void enable2D(GL gl) 
      { 
         // Java2D coord-system 
         gl.glMatrixMode(GL.GL_PROJECTION); 
         gl.glPushMatrix(); 
         gl.glLoadIdentity(); 
 
         gl.glScalef(1.0F / (w / 2), 1.0F / (h / 2), 1); 
         gl.glTranslatef(-w / 2, h / 2, 0); 
         gl.glScalef(1, -1, 1); 
 
         gl.glMatrixMode(GL.GL_MODELVIEW); 
         gl.glPushMatrix(); 
         gl.glLoadIdentity(); 
      } 
 
 
 
      private final void disable2D(GL gl) 
      { 
         gl.glMatrixMode(GL.GL_PROJECTION); 
         gl.glPopMatrix(); 
         gl.glMatrixMode(GL.GL_MODELVIEW); 
         gl.glPopMatrix(); 
      } 
   } 
 
   /** 
    * SHUT DOWN 
    */ 
 
   private class FrameShutdown extends WindowAdapter 
   { 
      public void windowClosing(WindowEvent event) 
      { 
         running = false; 
      } 
   } 
 
   private class KeyboardShutdown extends KeyAdapter 
   { 
      public void keyPressed(KeyEvent event) 
      { 
         if (event.getKeyCode() == KeyEvent.VK_ESCAPE) 
         { 
            running = false; 
         } 
      } 
   } 
}



---- Additional Comments From kbr 2005-01-31 01:26:58 ----

I can&apos;t reproduce this behavior. Fullscreen and windowed mode work identically
on my machine (Windows XP, NVidia Quadro FX Go700). The code should be
specifying canvas.setAutoSwapBufferMode(!forcedSwap) as far as I can tell in
order for it to exhibit the intended behavior. Regardless, as long as
sync-to-vertical-refresh is enabled, both boxes are shown.




--- Bug imported by sgothel@jausoft.com 2010-03-24 07:47 EDT  ---

This bug was previously known as _bug_ 115 at https://jogl.dev.java.net/bugs/show_bug.cgi?id=115
</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>