# OpenGl and ruby

**URL:** <https://www.ruby-forum.com/t/opengl-and-ruby/175096>\
**Category:** Ruby\
**Created:** [September 7, 2009, 10:54pm UTC](https://www.ruby-forum.com/t/opengl-and-ruby/175096 "2009-09-07T22:54:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unnown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/e0b2c6/32.png) [@unnown](https://www.ruby-forum.com/u/unnown)\
**Post date:** [September 7, 2009, 10:54pm UTC](https://www.ruby-forum.com/t/opengl-and-ruby/175096/1 "2009-09-07T22:54:10Z")

</div>

Hello all,

i have been working with ruby for less than a month now so sory if this  
is a stupid mistake

i have been trying to get ruby to work with opengl,  
i found an app which integrates ruby with gosu and opengl which is great  
for me

but,  
im trying to make a simple tile engine with opengl to show the actual  
tiles  
so i used gosu to load the tiles  
and then in opengl drawing it,

i have been messing with the code a lot so i’ts bugy,  
this is the class i have so far  
i know this should just draw one tile and not a whole range but thatÂ´s  
something i want to program myself.

can anybody please help me?

class OpenGL  
def initialize(window)  
@TextureImage = Gosu::Image.load\_tiles(window, “Media/Tiles.bmp”,  
32, 32, true)  
glClearColor(0.0, 0.0, 0.0, 0)  
glHint(GL\_PERSPECTIVE\_CORRECTION\_HINT,GL\_NICEST); # Really Nice  
Perspective Calculations  
glHint(GL\_POINT\_SMOOTH\_HINT,GL\_NICEST);  
gluPerspective(45.0, 800 / 600, 0.1, 100.0)

```
draw_gl(0,0,1)

```

end

def draw\_gl(x, y, tile)  
info = @TextureImage[tile].gl\_tex\_info  
return unless info  
glDepthFunc(GL\_GEQUAL)  
glEnable(GL\_DEPTH\_TEST)  
glEnable(GL\_BLEND)

```
glMatrixMode(GL_PROJECTION)
glLoadIdentity
glFrustum(-0.10, 0.10, -0.075, 0.075, 1, 100)

glMatrixMode(GL_MODELVIEW)
glLoadIdentity
glTranslate(0, 0, 1)

glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST)
glHint(GL_POINT_SMOOTH_HINT,GL_NICEST)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, info.tex_name)
glBegin(GL_TRIANGLE_STRIP)
  glColor4d(1, 1, 1, 0)
  glTexCoord2d(info.left, info.top)
  glVertex3d(-0.5, -0.5, 0)

  glColor4d(1, 255, 1, 0)
  glTexCoord2d(info.left, info.bottom)
  glVertex3d(-0.5, 0.5, 0)

  glColor4d(1, 1, 255, 0)
  glTexCoord2d(info.right, info.top)
  glVertex3d(0.5, -0.5, 0)

  glColor4d(255, 1, 1, 0)
  glTexCoord2d(info.right, info.bottom)
  glVertex3d(0.5, 0.5, 0)
glEnd

```

end  
end
