0
방금 Ruby-OpenGL로 프로그래밍하기 시작했습니다. Nehe 튜토리얼을 렌더러 클래스로 번역 했으므로 일부 간단한 3D 객체를 보여주는 데는 문제가 없습니다. 이제 이러한 개체에 텍스처를 적용하고 싶습니다. "texture.bmp"가 있지만 객체 위에 배치하는 방법은 무엇입니까?Ruby OpenGL : 비트 맵 텍스처를로드하고 3D 오브젝트에 배치하는 방법은 무엇입니까?
module RGLEngine
require "rubygems"
require "gl"
require "glu"
require "glut"
require "mathn"
require "yaml"
class Renderer
include Gl
include Glu
include Glut
attr_reader :width, :height
def initialize
@width = 640 # to be loaded from config.yaml
@height = 480
end
def render
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity
glTranslatef(-1.5, 0.0, -6.0)
# Draw Poylgons
# ...
# uncomment this for a simple example
#glBegin(GL_POLYGON)
# glVertex3f(0.0, 1.0, 0.0)
# glVertex3f(1.0, -1.0, 0.0)
# glVertex3f(-1.0, -1.0, 0.0)
#glEnd
glutSwapBuffers
end
def idle
glutPostRedisplay
end
def reshape(width, height)
if height == 0
height = 1
end
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity
gluPerspective(45.0, width/height, 0.1, 100.0)
end
def realize!
glutInit
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
glutInitWindowSize(@width, @height)
glutInitWindowPosition(0, 0)
window = glutCreateWindow("RGLEngine alpha")
glutDisplayFunc(method(:render).to_proc)
glutReshapeFunc(method(:reshape).to_proc)
glutIdleFunc(method(:idle).to_proc)
glClearColor(0.0, 0.0, 0.0, 0)
glClearDepth(1.0)
glDepthFunc(GL_LEQUAL)
glEnable(GL_DEPTH_TEST)
glEnable(GL_TEXTURE_2D)
glShadeModel(GL_SMOOTH)
glMatrixMode(GL_PROJECTION)
glLoadIdentity
gluPerspective(45.0, @width/@height, 0.1, 100.0)
glMatrixMode(GL_MODELVIEW)
glutMainLoop()
end
end
end
RGLEngine::Renderer.new.realize!