Forums Archived

The forums are being archived. See this topic for more information.

both rubygame and opengl

Get help and support with Rubygame

both rubygame and opengl

Postby red » Fri Jan 21, 2011 7:47 pm

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
red
 
Posts: 7
Joined: Thu Dec 30, 2010 6:26 pm

Re: both rubygame and opengl

Postby jacius » Sat Jan 22, 2011 12:48 am

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.
User avatar
jacius
Site Admin
 
Posts: 131
Joined: Fri Feb 06, 2009 11:13 pm

Re: both rubygame and opengl

Postby red » Sat Jan 22, 2011 12:49 pm

ok thank you. It's working
red
 
Posts: 7
Joined: Thu Dec 30, 2010 6:26 pm


Return to Help & Support

Who is online

Users browsing this forum: No registered users and 0 guests

cron