Jump to content

OpenGL won't render texture

- - - - -

  • Please log in to reply
No replies to this topic

#1
Groogy

Groogy

    Programmer

  • Members
  • PipPipPipPip
  • 183 posts
Hi!

I'm having some problem with getting my OpenGL ruby app to render the textures on a Quad. It's my "Image" class. More or less, I get a white box so it seems to be not applying the texture (If I change the color in modelview matrix then the box will be that color instead). I can't see if I've missed anything.

I think this code should be enough for a basic understanding of the problem:
def initialize_graphics
  graphics   = @settings.graphics
  resize_graphics graphics[:size][0], graphics[:size][1]

  # Setup more OpenGL stuff
  GL.ClearColor 0, 0, 0, 1.0
  GL.ClearDepth 1.0
  GL.Hint GL::PERSPECTIVE_CORRECTION_HINT, GL_NICEST
  GL.Enable GL::DEPTH_TEST
  GL.Enable GL::CULL_FACE
  GL.Enable GL::POINT_SMOOTH
  GL.Enable GL::LINE_SMOOTH
  GL.Enable GL::POLYGON_SMOOTH
  GL.Enable GL::TEXTURE_2D
  GL.Enable GL::BLEND
  GL.DepthFunc GL::ALWAYS
  GL.BlendFunc GL::SRC_ALPHA, GL_ONE

  @fps = UI::Text.new "0 FPS", [DEFAULT_FONT_PATH, 15], [255, 255, 0]
end

def pre_render x, y, z
  GL.MatrixMode GL::MODELVIEW
  GL.PushMatrix
  GL.Translate x, y, z

  @src_rect.x = @src_rect.x / width.to_f
  @src_rect.y = @src_rect.y / height.to_f
  @src_rect.w = @src_rect.w / width.to_f
  @src_rect.h = @src_rect.h / height.to_f
end

def post_render x, y, z
  @src_rect = nil
  GL.MatrixMode GL::MODELVIEW
  GL.PopMatrix
end

def render x, y, z
  bind_texture
  GL.Begin GL::QUADS
    # Top Left
    GL.TexCoord @src_rect.left, @src_rect.top
    GL.Vertex   0.0, 0.0, 0.0
    # Bottom Left
    GL.TexCoord @src_rect.left, @src_rect.bottom
    GL.Vertex   0.0, height, 0.0
    # Bottom Right
    GL.TexCoord @src_rect.right, @src_rect.bottom
    GL.Vertex   width, height, 0.0
    # Top Right
    GL.TexCoord @src_rect.right, @src_rect.top
    GL.Vertex   width, 0.0, 0.0
  GL.End
end

The image I'm trying to render is a 32bit image of the size 200x200. I know textures need to be of base 2. So does that mean that it must be dividable by 2 or that they must be like 8x* -> 16x* and so on? If that's the problem, should I modify the image directly or do it trough the application on the run(and how)?

**ADDITION**
Also saw that I had an image that had the size 1024x768 which I think is in that range of numbers. When rendering it only gives me that white box too so I don't think the textures size is the problem.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users