opengl and bypassing the java ui stuff for games

Put your problem here if it does not fit any of the other categories.

opengl and bypassing the java ui stuff for games

Postby supagu » Sun Mar 21, 2010 8:55 am

so im trying to make games, how ever i need to deal with the java UI concepts of views and canvases and such which means my games are event driven, which is not cool.

i dont want to be told when i should draw and when i should update, i want to control this my self.
how can i do this? I would like to avoid the NDK if possible, but every corner i turn the java way doesnt seem to get me any where.

so my idea has been to try to implement my own surfaceview, such that i can draw when ever i like, but i then need

this is what i've been screwing with:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. class TestAppView extends SurfaceView
  3.  
  4. {
  5.  
  6.         public TestAppView(Application app)
  7.  
  8.         {
  9.  
  10.                 // http://groups.google.com/group/android- ... c5003bb8fe
  11.  
  12.                
  13.  
  14.                 //http://groups.google.com/group/android-internals/browse_thread/thread/c37e36a805891682
  15.  
  16.                
  17.  
  18.                 // c++
  19.  
  20.                 //http://code.google.com/p/irrlicht-em/source/browse/branches/irrlicht-1.4_bt/source/Irrlicht/COpenGLESDriver.cpp?r=24
  21.  
  22.                
  23.  
  24.                 // http://java.sun.com/javame/reference/ap ... EGL10.html
  25.  
  26.                
  27.  
  28.                 // http://markmail.org/message/2japxvq3exj2w3pt
  29.  
  30.                
  31.  
  32.                 super(app);
  33.  
  34.                
  35.  
  36.                 // Get a Graphics instance for MIDP rendering
  37.  
  38.             // and to use in createWindowSurface
  39.  
  40.             //this.midpGraphics = getGraphics();
  41.  
  42.                
  43.  
  44.                
  45.  
  46.                
  47.  
  48.                 EGL10 egl = (EGL10)EGLContext.getEGL();
  49.  
  50.                
  51.  
  52.                 // Get the EGL display object and initialize EGL
  53.  
  54.                 EGLDisplay eglDisplay = EGL10.EGL_NO_DISPLAY;
  55.  
  56.                 eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
  57.  
  58.                
  59.  
  60.                 int[] major_minor = new int[2];
  61.  
  62.             egl.eglInitialize(eglDisplay, major_minor);
  63.  
  64.             System.out.println("EGL revision: major = " + major_minor[0]);
  65.  
  66.             System.out.println("EGL revision: minor = " + major_minor[1]);
  67.  
  68.                  
  69.  
  70.             // Determine the number of available configurations
  71.  
  72.             int[] num_config = new int[1];
  73.  
  74.             egl.eglGetConfigs(eglDisplay, null, 0, num_config);
  75.  
  76.             System.out.println("There are " + num_config[0] + " configurations");
  77.  
  78.              
  79.  
  80.             // Locate an 8/8/8 RGB configuration
  81.  
  82.                 int[] configSpec = { EGL10.EGL_RED_SIZE, 8,
  83.  
  84.                 EGL10.EGL_GREEN_SIZE, 8,
  85.  
  86.                 EGL10.EGL_BLUE_SIZE, 8,
  87.  
  88.                 EGL10.EGL_ALPHA_SIZE, EGL10.EGL_DONT_CARE,
  89.  
  90.                 EGL10.EGL_DEPTH_SIZE, EGL10.EGL_DONT_CARE,
  91.  
  92.                 EGL10.EGL_STENCIL_SIZE, EGL10.EGL_DONT_CARE,
  93.  
  94.                 EGL10.EGL_NONE
  95.  
  96.                 };
  97.  
  98.                
  99.  
  100.                 // Grab the first matching config
  101.  
  102.                 EGLConfig[] eglConfigs = new EGLConfig[1];
  103.  
  104.                 int[] numConfigs = new int[1];
  105.  
  106.         egl.eglChooseConfig(eglDisplay, configSpec, eglConfigs, 1, numConfigs);
  107.  
  108.        
  109.  
  110.         // Get a context for EGL rendering
  111.  
  112.         EGLConfig config = eglConfigs[0];
  113.  
  114.                 mGLContext = egl.eglCreateContext(eglDisplay, config, EGL10.EGL_NO_CONTEXT, null);
  115.  
  116.                
  117.  
  118.                 // Get a GL object for rendering
  119.  
  120.                 mGL = (GL10)mGLContext.getGL();
  121.  
  122.  
  123.  
  124.                 // FMNOTE: NOW WHAT????
  125.  
  126.                
  127.  
  128.                 // Get a Graphics instance for MIDP rendering
  129.  
  130.              // and to use in createWindowSurface
  131.  
  132.              //this.midpGraphics = app.getGraphics();
  133.  
  134.              
  135.  
  136.             // Bind a window surface to the context
  137.  
  138.             EGLSurface eglSurface = egl.eglCreateWindowSurface(eglDisplay, config, this, null);
  139.  
  140.             //if (m_eglContext == EGL_NO_CONTEXT || eglGetError() != EGL_SUCCESS)
  141.  
  142.             //  System.out.println("failed " + eglGetError());
  143.  
  144.             //else
  145.  
  146.             //  System.out.println("It passed on eglCreateContext! %d \n ",eglGetError());
  147.  
  148.  
  149.  
  150.             // Make the context current for future GL calls
  151.  
  152.             egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, mGLContext);
  153.  
  154.         }
  155.  
  156.        
  157.  
  158.         GL10            mGL;
  159.  
  160.         EGLContext      mGLContext;
  161.  
  162.         //Graphics      mGraphics;
  163.  
  164. }
  165.  
  166.  
Parsed in 0.040 seconds, using GeSHi 1.0.8.4


i use setContentView on my activity, how ever im stuck at the point where i'm using eglCreateWindowSurface
this isnt working and not even sure if im on the right path!
supagu
Developer
Developer
 
Posts: 32
Joined: Sun Jun 07, 2009 3:50 am

Top

Postby Emmanuel7 » Sun Mar 21, 2010 1:36 pm

I think you have essentially missed the GLSurfaceView.

It's a special view for OpenGL, that will deal with all the boring thing for you, and call the OnDraw method every trame.

Emmanuel / Alocaly
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Postby supagu » Mon Mar 22, 2010 10:14 am

the problem is GLSurfaceView is still event driven, you have to put your drawing code in onDrawFrame
supagu
Developer
Developer
 
Posts: 32
Joined: Sun Jun 07, 2009 3:50 am

Postby Emmanuel7 » Mon Mar 22, 2010 2:09 pm

supagu wrote:the problem is GLSurfaceView is still event driven, you have to put your drawing code in onDrawFrame

True, but the OnDrawFrame method is called continuously - unless you stated it not to behave this way -.

I really think it has been designed to solve your issue, and that you should give it a try.
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 21 guests