OpenGl and ruby

Discussion in 'Ruby' started by Thijs Leeflang, Sep 7, 2009.

  1. 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
    --
    Posted via http://www.ruby-forum.com/.
    Thijs Leeflang, Sep 7, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alwin Blok

    ruby-opengl, ruby-glut

    Alwin Blok, Dec 30, 2003, in forum: Ruby
    Replies:
    5
    Views:
    184
    Alwin Blok
    Jan 21, 2004
  2. David Ross
    Replies:
    1
    Views:
    140
    Kaspar Schiess
    Sep 14, 2004
  3. Robert Maus

    Ruby and Opengl samples

    Robert Maus, Jan 9, 2006, in forum: Ruby
    Replies:
    0
    Views:
    80
    Robert Maus
    Jan 9, 2006
  4. anne001

    OpenGL and Ruby?

    anne001, Jan 15, 2006, in forum: Ruby
    Replies:
    7
    Views:
    171
    anne001
    Jan 16, 2006
  5. Matthew Carlin

    Embedded Ruby and OpenGL

    Matthew Carlin, Jul 26, 2006, in forum: Ruby
    Replies:
    0
    Views:
    76
    Matthew Carlin
    Jul 26, 2006
Loading...

Share This Page