Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Forum
Search
Topic Problem to tile a texture in a single quad By Zohran Date 2022-03-01 00:02
Hello, I'm learning actually how to use OpenGL with Ruby. I done this simple scene class actually to test all OpenGL capability. And I have a problem with my part titled: #DRAW THE GROUND
I would like to draw this quad with the texture as tiled. I try to change every thing, but nothing. Every time this quad show only one time my texture. What is the problem ? I recognize I'm a little bit lost with the U/V coordinates and 3D coordinates of my vertex when I'm using a texture. For example, with textured quad, how can I set the angle of my quad ?:

class Test3D < GameScene

  def initialize
    @texture = Gosu::Image.new('Test.png')
    @texture1 = Gosu::Image.new('Test1.png', {tileable: true})
    @texture2 = Gosu::Image.new('Tree.png')
    @texture3 = Gosu::Image.new('Character.png')

    @backgroundMusic = Gosu::Song.new("Test.wav")
    @backgroundMusic.play(true)
  end

  def draw
    Gosu.gl do

      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
      glEnable(GL_TEXTURE_2D)
      glEnable(GL_DEPTH_TEST)
      glMatrixMode(GL_PROJECTION)
      glLoadIdentity
      gluPerspective(45.0, $gameWindow.width.to_f / $gameWindow.height.to_f, 1, 1000)
      glMatrixMode(GL_MODELVIEW)
      glLoadIdentity
      gluLookAt(0,-640,250,0,0,0,0,0,1)

      #DRAW THE BUILDING
      glBindTexture(GL_TEXTURE_2D, @texture.gl_tex_info.tex_name)

      glPushMatrix
        glScalef(@texture.width, 0, @texture.height)

        glBegin(GL_QUADS)
          glTexCoord2d(@texture.gl_tex_info.left,@texture.gl_tex_info.bottom)
          glVertex3f(-0.5, 0.0, 0.0)

          glTexCoord2d(@texture.gl_tex_info.right,@texture.gl_tex_info.bottom)
          glVertex3f(0.5, 0.0, 0.0)

          glTexCoord2d(@texture.gl_tex_info.right,@texture.gl_tex_info.top)
          glVertex3f(0.5, 0.0, 1.0)

          glTexCoord2d(@texture.gl_tex_info.left,@texture.gl_tex_info.top)
          glVertex3f(-0.5, 0.0, 1.0)
        glEnd
      glPopMatrix

      #DRAW THE GROUND
      glBindTexture(GL_TEXTURE_2D, @texture1.gl_tex_info.tex_name)

      glPushMatrix
        glScalef(@texture1.width, @texture1.height, 0)

        glBegin(GL_QUADS)
          glTexCoord2d(@texture1.gl_tex_info.left,@texture1.gl_tex_info.bottom)
          glVertex3f(-512/2, -512/2, 0.0)

          glTexCoord2d(@texture1.gl_tex_info.right,@texture1.gl_tex_info.bottom)
          glVertex3f(512/2, -512/2, 0.0)

          glTexCoord2d(@texture1.gl_tex_info.right,@texture1.gl_tex_info.top)
          glVertex3f(512/2, 512/2, 0.0)

          glTexCoord2d(@texture1.gl_tex_info.left,@texture1.gl_tex_info.top)
          glVertex3f(-512/2, 512/2, 0.0)
        glEnd
      glPopMatrix

      #DRAW A TREE
      glBindTexture(GL_TEXTURE_2D, @texture2.gl_tex_info.tex_name)
      glEnable(GL_ALPHA_TEST)
      glAlphaFunc(GL_GREATER,0)

      glPushMatrix
      glTranslatef(64*3,64,0)
      glScalef(@texture2.width,@texture2.height, @texture2.height)

        glBegin(GL_QUADS)
          glTexCoord2d(@texture2.gl_tex_info.left,@texture2.gl_tex_info.bottom)
          glVertex3f(-0.5, 0.0, 0.0)

          glTexCoord2d(@texture2.gl_tex_info.right,@texture2.gl_tex_info.bottom)
          glVertex3f(0.5, 0.0, 0.0)

          glTexCoord2d(@texture2.gl_tex_info.right,@texture2.gl_tex_info.top)
          glVertex3f(0.5, 0.0, 1.0)

          glTexCoord2d(@texture2.gl_tex_info.left,@texture2.gl_tex_info.top)
          glVertex3f(-0.5, 0.0, 1.0)
        glEnd

      glDisable(GL_ALPHA_TEST)
      glPopMatrix

      #DRAW A CHARACTER
      glBindTexture(GL_TEXTURE_2D, @texture3.gl_tex_info.tex_name)
      glEnable(GL_ALPHA_TEST)
      glAlphaFunc(GL_GREATER,0)

      glPushMatrix
      glTranslatef(0,-64,1)
        glScalef(@texture3.width,@texture3.height,@texture3.height)

        glBegin(GL_QUADS)
          glTexCoord2d(@texture3.gl_tex_info.left,@texture3.gl_tex_info.bottom)
          glVertex3f(-0.5, 0.0, 0.0)

          glTexCoord2d(@texture3.gl_tex_info.right,@texture3.gl_tex_info.bottom)
          glVertex3f(0.5, 0.0, 0.0)

          glTexCoord2d(@texture3.gl_tex_info.right,@texture3.gl_tex_info.top)
          glVertex3f(0.5, 0.0, 1.0)

          glTexCoord2d(@texture3.gl_tex_info.left,@texture3.gl_tex_info.top)
          glVertex3f(-0.5, 0.0, 1.0)
        glEnd
      glDisable(GL_ALPHA_TEST)
      glPopMatrix

    end

  end

end
Topic Problem with Opengl now... Yeah ! By Zohran Date 2015-11-14 15:41
I thinks i miss my OpenGL installation, but gosu example runs x) sorry, i don't know this gems, sorry :x
Thanks !
Topic Problem with Opengl now... Yeah ! By Zohran Date 2015-11-12 10:32
Hello, thanks for your first help for install gosu and texplay, now it's good, but sorry xD i have other problem.

When i would like to test OpenGL with rubyfile test in C:\Ruby22\lib\ruby\gems\2.2.0\gems\opengl-0.9.2\test, file don't work, i have this bug (Glu gem is installed) :
[http://img11.hostingpics.net/pics/532690Sanstitre.png]
Topic Problem for install Gosu By Zohran Date 2015-11-12 10:27
Thanks you, it's good !
Topic Problem for install Gosu By Zohran Date 2015-11-11 23:09
I have installed gosu with gem install gosu --pre when i have test gem install texplay, but it does'nt work... if I understood what you wanted me to do. :C
Topic Problem for install Gosu By Zohran Date 2015-11-11 10:29
Okay, i have installed 32 bits version of ruby. Thanks for help mans ! :)
But.... T_T
[http://img11.hostingpics.net/pics/771018Sanstitre.png]
Topic Problem for install Gosu By Zohran Date 2015-11-11 01:32
Thanks you very muhc ! I have installed Gosu ! :)

But i have second problem, i have similary bug when i try to install texplay. It's possible to update it?
Topic Problem for install Gosu By Zohran Date 2015-11-08 22:42
Thanks you very much, i wait that ! :)
Topic Problem for install Gosu By Zohran Date 2015-11-07 20:57
Yes, i do it... but no result :C

Look that:
[http://img15.hostingpics.net/pics/91393418bg.png]
Topic Problem for install Gosu By Zohran Date 2015-11-06 22:14
Ello, i'm french, sorry for my bad English.
I have problem when i would like to install Gosu gem file. I never have this problem in past...
[http://img15.hostingpics.net/pics/32396524bg.png]

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill