Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Active rendering with JOGL  (Read 4356 times)
0 Members and 1 Guest are viewing this topic.
Offline DzzD
« Posted 2007-11-07 00:48:57 »

NB: this post is due to a question in JOGL board, as it is a shared code, I thought it should be good to post it here too

This explain a simple way to make active rendering with JOGL without GLEventListener

Render class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
import java.awt.*;
import java.awt.event.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;

public final class RenderJOGL
{  
   private GLContext context;
   private GLCanvas canvas;
   private GL gl;
   private GLU glu;

   public Canvas getCanvas()
   {
      return this.canvas;
   }
   
   public RenderJOGL() throws Throwable
   {
      GLCapabilities glCaps = new GLCapabilities();  
      glCaps.setRedBits(8);
      glCaps.setBlueBits(8);
      glCaps.setGreenBits(8);
      glCaps.setAlphaBits(8);
      glCaps.setDoubleBuffered(true);
      glCaps.setHardwareAccelerated(true);

      this.canvas = new GLCanvas(glCaps);
      this.canvas.setAutoSwapBufferMode(false);
      this.glu=new GLU();

      this.context=this.canvas.getContext();
      this.gl = this.context.getGL();
   }
   
   public void setSize(int viewPixelWidth,int viewPixelHeight)//,int maxAntialias)
   {
      this.canvas.setSize(viewPixelWidth,viewPixelHeight);
   }      
   
   public void render()
   {  
      this.makeContentCurrent();

      this.gl.glDisable(GL.GL_DEPTH_TEST);
      gl.glClearColor(0.0f,0.0f,1.0f,0.0f);   //Background blue
              gl.glClear(GL.GL_COLOR_BUFFER_BIT);
              gl.glLoadIdentity();  
              gl.glColor3f(1.0f, 0.0f, 0.0f);   //Color red
              gl.glBegin(GL.GL_TRIANGLES);
              gl.glVertex3f(0,0,0.0f);
              gl.glVertex3f(1,0,0.0f);
              gl.glVertex3f(0,1,0.0f);        
              gl.glEnd();  

              this.context.release();
      this.canvas.swapBuffers();
   }
   
   private void makeContentCurrent()
   {  
      try
      {
         while (context.makeCurrent() == GLContext.CONTEXT_NOT_CURRENT)
         {
            System.out.println("Context not yet current...");
            Thread.sleep(100);
         }
      }
      catch (InterruptedException e)
      {
          e.printStackTrace();
      }
   }          
}


AppletTest class:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
 
import java.awt.*;
import java.applet.*;
import java.io.*;
import java.awt.event.*;

public class AppletTest extends Applet implements Runnable
{
   private int nbloop;
   private RenderJOGL render;
   
   private long startTime;
   private Thread process;
   private int nbStart;
   

   public void init()
   {
      this.nbStart=0;
   }
   
   public void start()
   {
      //Ensure that start is only called once
      if(this.nbStart!=0)
         return;
      this.nbStart++;
     
      this.render=new RenderJOGL();      
     
      //Add Render canvas to this applet
      this.setLayout(null);
      Canvas canvas=this.render.getCanvas();
      this.add(canvas);
      this.render.setSize(this.getWidth(),this.getHeight());
     
      //Start rendering Thread
      this.process=new Thread(this);
      this.process.start();
   }
   
   public void run()
   {
      try
      {
         while(true)
         {
            this.render.render();
            Thread.sleep(10);
         }
      }
      catch(InterruptedException ie)
      {
      }
   }
     
}


EDIT: Maybe you will have some few modifications to make it works properly, as it is a Class comming from 3DzzD API, simplified for a better understanding,  so I havn't tested it....

let me know if it helps!

Offline gouessej
« Reply #1 - Posted 2008-03-06 23:00:52 »

Do you really think active rendering can improve the performance? Instead of sharing 3DzzD source code by small pieces, why don't you open the whole source code???

Offline DzzD
« Reply #2 - Posted 2008-03-07 17:20:08 »

Quote
Do you really think active rendering can improve the performance?
No, it don't think it will hugely improve performance but I found that give a better control over the rendering process.


Quote
Instead of sharing 3DzzD source code by small pieces, why don't you open the whole source code???
hey! Smiley that's exacly what I was thinking about this week !?, I dont really know the steps to do this, I mean steps to make a project opensourced in a good way ?

what I am affraid about is multiplicity of version, bugs add, and such !?

anyway, you are right I must share the whole and that what I am going to do, just need to found a good way to do that, It will be a lot better experience for user and will give a better control.

any idea to how opensourcing the whole in a good way are welcome, this is not really a world I know  ?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2008-03-10 05:46:40 »

No, it don't think it will hugely improve performance but I found that give a better control over the rendering process.

 hey! Smiley that's exacly what I was thinking about this week !?, I dont really know the steps to do this, I mean steps to make a project opensourced in a good way ?

what I am affraid about is multiplicity of version, bugs add, and such !?

anyway, you are right I must share the whole and that what I am going to do, just need to found a good way to do that, It will be a lot better experience for user and will give a better control.

any idea to how opensourcing the whole in a good way are welcome, this is not really a world I know  ?
Look at my source code, I only put the license (the complete text) in the ZIP and I put a reference to this in each file. I chose the GPL license version 2 to be sure that anyone can use my source code if he accepts to share his own source code too.

Offline DzzD
« Reply #4 - Posted 2008-03-10 13:41:39 »

Thanks, I will look on it, It may take up to two weeks for me too opensource the whole 3DzzD project as I would like to give public a clean project and because I dont work a lot on it for now as I am quite busy  Sad.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (31 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (60 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!