Page 1 of 1

both rubygame and opengl

PostPosted: Fri Jan 21, 2011 7:47 pm
by red
I'm using ffi-opengl and everything is going smoothly but glutBitmapCharacter isn't working because fonts are supposedly uninitialized.
Anyway I was wondering if I can both draw things with opengl and rubygame. I need to draw text on opengl window with rubygame but I need a surface for it. I don't know how to return screen surface in my setup_screen function.

Code: Select all
  def setup_screen( size=[640,480], fovy=45, clip=[0.1,100] )
   w, h = size
   GL.set_attrib( RED_SIZE, 8)
   GL.set_attrib( GREEN_SIZE, 8)
   GL.set_attrib( BLUE_SIZE, 8)
   GL.set_attrib( DEPTH_SIZE, 16)
   GL.set_attrib( DOUBLEBUFFER, 1)
   Screen.set_mode([w,h], 24, OPENGL)
   glViewport( 0, 0, w, h )
   glMatrixMode( GL_PROJECTION )
   glLoadIdentity()
   gluPerspective( fovy, w/(h.to_f), clip[0], clip[1])
   glEnable(GL_DEPTH_TEST)
   glDepthFunc(GL_LESS)
   glEnable(GL_TEXTURE_2D)
  end

Re: both rubygame and opengl

PostPosted: Sat Jan 22, 2011 12:48 am
by jacius
Alas, you can't use the normal Rubygame draw methods to draw on the screen when using OpenGL; this is a limitation of SDL. But, you can either use OpenGL drawing functions, or create a non-screen Rubygame Surface, draw (or render text) on that, and then use that Surface as a texture in OpenGL.

I recommend having a look at demo_opengl.rb, a sample application I wrote that uses Rubygame with OpenGL. (That file is not yet shipped with any version of Rubygame, but it's in the repository.) In particular, you will probably be interested in the Cube#setup_texture method, which converts the Rubygame (SDL) Surface to an OpenGL texture. If your Surface has an alpha channel, you should use GL_RGBA instead of GL_RGB.

Hope that helps.

Re: both rubygame and opengl

PostPosted: Sat Jan 22, 2011 12:49 pm
by red
ok thank you. It's working