Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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  
  Some noobish GL4Java questions  (Read 1688 times)
0 Members and 1 Guest are viewing this topic.
Offline pr0.n00b

Junior Newbie




Java games rock!


« Posted 2002-12-28 04:53:46 »

Hi,

after playing a while with Java and the creation of a very basic tile-engine using java 1.4.0 with it's VolatileImage where I allready got an application into exclusive fullscreenmode I now started to play around with GL4Java and the NeHe ports to Java. But I have no idea get the sample Applets turned into applications which maybe also should run in fullscreen.

Anyone here can help me please?
Offline sheijk

Junior Newbie




mwuah?


« Reply #1 - Posted 2002-12-28 22:20:31 »

Quote
But I have no idea get the sample Applets turned into applications which maybe also should run in fullscreen.

I had the same problem some days ago..
Here's my solution (without fullscreen)
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  
// create a panel which supports OpenGL (true for double buffering)
GLJPanel thePanel = new GLJPanel(true);
JFrame theFrame = new JFrame();

// insert frame init code like setting size etc.

// put the openGL panel into the frame
theFrame.getContentPane().add(thePanel);
            theFrame.setVisible(true);

// add an opengl listener
thePanel.addGLEventListener( new GLEventListener() {
      /** @see gl4java.drawable.GLEventListener#init(GLDrawable) */
      public void init(GLDrawable arg0) {
      }

      /** @see gl4java.drawable.GLEventListener#preDisplay(GLDrawable) */
      public void preDisplay(GLDrawable in_Draw) {
            in_Draw.getGL().glMatrixMode(GLEnum.GL_PROJECTION_MATRIX);
            in_Draw.getGL().glLoadIdentity();
                                   
            in_Draw.getGLU().gluPerspective(45.0f,
                  (float)in_Draw.getSize().width /
                  (float)in_Draw.getSize().height,
                  0.1f, 100.0f);
      }

      /** @see 4java.drawable.GLEventListener#display(GLDrawable) */
      public void display(GLDrawable arg0) {
            arg0.getGL().glClearColor(0, 0, 0, 0);
            arg0.getGL().glClear(GL_COLOR_BUFFER_BIT);
            // insert your display code here
     }

      /** @see gl4java.drawable.GLEventListener#postDisplay(GLDrawable) */
      public void postDisplay(GLDrawable arg0) {
      }

      /** @see gl4java.drawable.GLEventListener#cleanup(GLDrawable) */
      public void cleanup(GLDrawable arg0) {
      }

      /**@see gl4java.drawable.GLEventListener#reshape(GLDrawable, int, int) */
      public void reshape(GLDrawable arg0, int arg1, int arg2) {
      }
});      

// call this to invoke the paint function
thePanel.paint(theFrame.getContentPane().getGraphics());

This method may be far from optimal (especially placing the matrice setting code in the preDisplay might be nonsense) but at least it works. Smiley

btw: there isn't any new GLEventAdapter class like these for WindowAdapter etc., is there?
Offline pr0.n00b

Junior Newbie




Java games rock!


« Reply #2 - Posted 2002-12-28 23:42:37 »

After some trying here my version, contains parts of the tutors #4 and #34 from gametutorials.com to show something and to get the fps...

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  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
196  
197  
198  
199  
200  
201  
202  
203  
204  
205  
206  
207  
208  
209  
210  
211  
212  
213  
214  
215  
216  
217  
218  
219  
220  
221  
222  
223  
224  
225  
226  
227  
228  
229  
230  
231  
232  
233  
234  
235  
236  
237  
238  
239  
240  
241  
242  
243  
244  
245  
246  
247  
248  
import java.awt.*;
import java.awt.event.*;

import gl4java.awt.*;
import gl4java.utils.glut.*;
import gl4java.utils.glut.fonts.*;


public class Test01 extends Frame implements Runnable
{
      renderCanvas canvas = null;
      GraphicsDevice       myDevice;
    DisplayMode       oldMode, newMode;
   
      boolean                  fullscreen = false;
      int                   ScreenWidth = 800, ScreenHeight = 600, BitDepth = 32;            
     
      public static void main( String args[] )
      {
          new Test01();
      }
     
      public Test01()
      {
            super("Lalala");
              addWindowListener( new FensterAdapter() );
                         
              setSize(ScreenWidth, ScreenHeight);
            setResizable(false);
           
            myDevice = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
            oldMode = myDevice.getDisplayMode();
            newMode = new DisplayMode(ScreenWidth, ScreenHeight, BitDepth, oldMode.getRefreshRate());
     
              start();
      }

      public void start()
      {
            Thread th = new Thread (this);
            th.start ();
            Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
           
            canvas = new renderCanvas(getSize().width, getSize().height);
        add("Center", canvas);
       
        if (fullscreen) {
                  if(myDevice.isFullScreenSupported()) {
                        try {
                              this.setUndecorated(true);
                              myDevice.setFullScreenWindow(this);
                              myDevice.setDisplayMode(newMode);
                        }
                        catch (Exception e) {
                              myDevice.setDisplayMode(oldMode);
                }
                  }
                  else {
                        System.out.print("Vollbildmodus wird nicht unterst├╝tzt");
                        System.exit(0);
                  }
            }
            else {
                  setVisible(true);
            }      
      }
     
      public void run()
      {
            while (true) {
                  repaint();
                  try { Thread.sleep(0); }
                  catch (InterruptedException ex) { }
            }
      }
}

class renderCanvas extends GLAnimCanvas implements KeyListener
{
      boolean[] keys=new boolean[256];                                          // holds information on which keys are held down.
     static float framesPerSecond            = 0.0f;                              // This will store our fps
     static long lastTime                        = 0;                              // This will hold the time from the last frame
     static String strFrameRate;                                                      // We will store the string here for the window title
     static float rotY = 0;                                                            // This is used for the rotation degree
     
      int FONT_HEIGHT = 24;
      protected GLUTFunc glut = null;
     
      public renderCanvas(int w, int h)
      {
            super(w,h);
            addKeyListener(this);
            glut = new GLUTFuncLightImplWithFonts(gl, glu);
      }

      void PositionText( int x, int y )
      {
            gl.glPushAttrib( GL_TRANSFORM_BIT | GL_VIEWPORT_BIT );
            gl.glMatrixMode( GL_PROJECTION );                                    // Set our matrix to our projection matrix
           gl.glPushMatrix();                                                            // Push on a new matrix to work with
           gl.glLoadIdentity();                                                      // reset the matrix
           gl.glMatrixMode( GL_MODELVIEW );                                    // Set our matrix to our model view matrix
           gl.glPushMatrix();                                                            // Push on a new matrix to work with
           gl.glLoadIdentity();                                                      // Reset that matrix
           y = this.getHeight() - FONT_HEIGHT - y;                              // Calculate the weird screen position
           gl.glViewport( x - 1, y - 1, 0, 0 );                              // Create a new viewport to draw into
           gl.glRasterPos4f( 0, 0, 0, 1 );                                          // Set the drawing position
           gl.glPopMatrix();                                                            // Pop the current modelview matrix off the stack
           gl.glMatrixMode( GL_PROJECTION );                                    // Go back into projection mode
           gl.glPopMatrix();                                                            // Pop the projection matrix off the stack
           gl.glPopAttrib();                                                            // This restores our TRANSFORM and VIEWPORT attributes
     }

      void glDrawText(int x, int y, String strString)
      {
            PositionText(x, y);                                                            
            glut.glutBitmapString(glut.GLUT_BITMAP_TIMES_ROMAN_24,strString);
      }

      void CalculateFrameRate()
      {
            long currentTime = System.currentTimeMillis()/1000;                        
            ++framesPerSecond;
            if( currentTime - lastTime > 1.0f )
            {
                  lastTime = currentTime;
                  strFrameRate = "FPS: "+ framesPerSecond;
                  framesPerSecond = 0;
            }
            gl.glColor3f(0f, 1f, 0f);      
            glDrawText(0, 0, strFrameRate);
      }

      public void preInit()
      {
            setUseFpsSleep(false);                                                      //We want to run this animation at full speed. :)
     }

      public void init()
      {
            gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);                        //This will clear the background color to Black
           gl.glEnable(GL_DEPTH_TEST);                                                //Enables Depth Testing
           reshape(getSize().width, getSize().height);                        //Reshape the drawing canvas
           start();                                                                        //Start the animation
     }

      public void doCleanup()
      {
            stop();                                                                              //Stop the animation
     }

      public void reshape(int width, int height)
      {
            gl.glViewport(0,0,width,height);                                    // Make our viewport the whole window
           gl.glMatrixMode(GL_PROJECTION);                                          // Select The Projection Matrix
           gl.glLoadIdentity();                                                      // Reset The Projection Matrix
           glu.gluPerspective(45.0f,(float)width/(float)height, 1 ,150.0f);
            gl.glMatrixMode(GL_MODELVIEW);                                          // Select The Modelview Matrix
           gl.glLoadIdentity();                                                      // Reset The Modelview Matrix
     }

      public void display()
      {
            //Ensure GL is initialized correctly
           if (glj.gljMakeCurrent() == false) return;

            gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);      // Clear The Screen And The Depth Buffer
           gl.glLoadIdentity();                                                      // Reset The matrix
           
            //                    Position     View              Up Vector
           glu.gluLookAt(0, 0, 6,     0, 0, 0,     0, 1, 0);            // This determines where the camera's position and view is
           gl.glRotatef(rotY, 0, 1, 0);
            rotY += 2;

            gl.glBegin (GL_TRIANGLES);                                                // This is our BEGIN to draw
                 gl.glColor3f(1, 0, 0);                                                // Make the top vertex RED
                 gl.glVertex3f(0, 1, 0);                                                // Here is the top point of the triangle
                 gl.glColor3f(0, 1, 0);                                                // Make the left vertex GREEN
                 gl.glVertex3f(-1, 0, 0);                                          // Here is the left point of the triangle
                 gl.glColor3f(0, 0, 1);                                                // Make the right vertex BLUE
                 gl.glVertex3f(1, 0, 0);                                                // Here is the right point of the triangle
           gl.glEnd();                                                                        // This is the END of drawing

            CalculateFrameRate();
            ProcessKeyboard();                                                            // Process Keyboard Results

            //Swap buffers, check for errors, and release the drawing context
           glj.gljSwap();
            glj.gljCheckGL();
            glj.gljFree();
      }

      // Process Keyboard Results
     void ProcessKeyboard()                                                                  
      {
            if(keys[KeyEvent.VK_ESCAPE]) {
                  keys[KeyEvent.VK_ESCAPE] = false;
                  doCleanup();
                    System.exit(0);
              }
      }

      // These Methods Override the default implementation of MouseListener in GLAnimCanvas
     public void mouseEntered( MouseEvent evt )
      {
            Component comp = evt.getComponent();
            if( comp.equals(this ) )
            {
                  requestFocus();
            }
      }

      public void mouseClicked( MouseEvent evt )
      {
            Component comp = evt.getComponent();
            if( comp.equals(this ) )
            {
                  requestFocus();
            }
      }

      // Invoked when a key has been typed. This event occurs when a key press is followed by a key release.
     public void keyTyped(KeyEvent e)
      {
      }

      // Invoked when a key has been pressed.
     public void keyPressed(KeyEvent e)
      {
            if(e.getKeyCode()<250)            // only interested in first 250 key codes
                 keys[e.getKeyCode()]=true;      
      }

      // Invoked when a key has been released.
     public void keyReleased(KeyEvent e)
      {
            if(e.getKeyCode()<250)            // only interested in first 250 key codes
                 keys[e.getKeyCode()]=false;      
      }
}

class FensterAdapter extends WindowAdapter
{
      public void windowClosing ( WindowEvent e)
      {
            System.exit(0);
      }
}


The fps on my xp1700+ with gf4 ti4200 are horrible ~180 @800*600*32 windowed and ~200 in fullscreen.
(Q3 timedemo gives me more then 300fps^^)
Is java so slow? are there any big mistakes that slows everthing down?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2002-12-29 09:37:58 »

The problem is using threads here. That's just how GL4Java is designed to work though.

Cas Smiley

Offline pr0.n00b

Junior Newbie




Java games rock!


« Reply #4 - Posted 2002-12-29 12:45:47 »

If I remove my thread it's even slower.
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2002-12-29 20:11:04 »

Can't think why it should be. I get hundreds of fps using LWJGL...

Cas Smiley

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.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (40 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!