2008-10-28 4 views
1

move independently이므로, 텍스처에 pyglet 라벨을 렌더링해야합니다. 그렇지 않으면 각 글리프의 버텍스 목록을 업데이트하는 것이 너무 느립니다.OpenGL은 버텍스 컬러로 텍스처 색상을 설정합니다.

나는이 작업을 수행 할 수있는 솔루션을 가지고 있지만, 내 문제는, 캐릭터를 포함한 질감이 검은 색이다,하지만 난 그게 빨간색 싶습니다. 아래 예를 참조하십시오.

from pyglet.gl import * 

def label2texture(label): 
    vertex_list = label._vertex_lists[0].vertices[:] 
    xpos = map(int, vertex_list[::8]) 
    ypos = map(int, vertex_list[1::8]) 
    glyphs = label._get_glyphs() 

    xstart = xpos[0] 
    xend = xpos[-1] + glyphs[-1].width 
    width = xend - xstart 

    ystart = min(ypos) 
    yend = max(ystart+glyph.height for glyph in glyphs) 
    height = yend - ystart 

    texture = pyglet.image.Texture.create(width, height, pyglet.gl.GL_RGBA) 

    for glyph, x, y in zip(glyphs, xpos, ypos): 
     data = glyph.get_image_data() 
     x = x - xstart 
     y = height - glyph.height - y + ystart 
     texture.blit_into(data, x, y, 0) 

    return texture.get_transform(flip_y=True) 

window = pyglet.window.Window() 
label = pyglet.text.Label('Hello World!', font_size = 36) 
texture = label2texture(label) 

@window.event 
def on_draw(): 
    hoff = (window.width/2) - (texture.width/2) 
    voff = (window.height/2) - (texture.height/2) 

    glClear(GL_COLOR_BUFFER_BIT) 
    glEnable(GL_BLEND) 
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 
    glClearColor(0.0, 1.0, 0.0, 1.0) 
    window.clear() 
    glEnable(GL_TEXTURE_2D); 

    glBindTexture(GL_TEXTURE_2D, texture.id) 
    glColor4f(1.0, 0.0, 0.0, 1.0) #I'd like the font to be red 
    glBegin(GL_QUADS); 
    glTexCoord2d(0.0,1.0); glVertex2d(hoff,voff); 
    glTexCoord2d(1.0,1.0); glVertex2d(hoff+texture.width,voff); 
    glTexCoord2d(1.0,0.0); glVertex2d(hoff+texture.width,voff+texture.height); 
    glTexCoord2d(0.0,0.0); glVertex2d(hoff, voff+texture.height); 
    glEnd(); 

pyglet.app.run() 

어떻게 색을 칠할 수 있습니까?

답변

0

데칼링을 사용할 때 glTexEnv()을 통해 그렇게하지 않습니까?

2

glEnable(GL_COLOR_MATERIAL)으로 설정하고 싶습니다. 이렇게하면 텍스처 색상이 현재 OpenGL 색상과 혼합됩니다. glColorMaterial 함수를 사용하여 각 다각형의 앞/뒤/양쪽 모두에 영향을 주는지 여부를 지정할 수 있습니다. 문서 here

관련 문제