0

私は python を使用していますが、OpenGL は他の言語とほぼ同じ方法で行われます。

問題は、フレーム バッファ オブジェクトを使用してテクスチャまたはテクスチャへのラインをレンダリングしようとすると、逆さまにレンダリングされ、左下隅が小さすぎることです。とても奇妙です。実演するためにこれらの写真があります:

こう見えて、

www.godofgod.co.uk/my_files/Incorrect_operation.png

これは、代わりにpygameを使用していたときの様子です。Pygame は遅すぎることを学びました。私のゲームは、OpenGL の速度がなければプレイできません。曲がった角は無視してください。私はまだ OpenGL でそれらを実装していません。まずこの問題を解決する必要があります。

www.godofgod.co.uk/my_files/Correct_operation.png

深さは使っていません。

この不規則な動作の原因は何ですか。これがコードです(関数は実際のコードでインデントされています。正しく表示されます)、便利な場合があります。

def texture_to_texture(target,surface,offset): #Target is an object of a class which contains texture data. This texture should be the target. Surface is the same but is the texture which should be drawn onto the target. offset is the offset where the surface texture will be drawn on the target texture.
#This will create the textures if not already. It will create textures from image data or block colour. Seems to work fine as direct rendering of textures to the screen works brilliantly.
if target.texture == None:
    create_texture(target)
if surface.texture == None:
    create_texture(surface)
frame_buffer =  glGenFramebuffersEXT(1)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frame_buffer)
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, target.texture, 0) #target.texture is the texture id from the object
glPushAttrib(GL_VIEWPORT_BIT)
glViewport(0,0,target.surface_size[0],target.surface_size[1])
draw_texture(surface.texture,offset,surface.surface_size,[float(c)/255.0 for c in surface.colour]) #The last part changes the 0-255 colours to 0-1 The textures when drawn appear to have the correct colour. Don't worry about that.
glPopAttrib()
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
glDeleteFramebuffersEXT(1, [int(frame_buffer)]) #Requires the sequence of the integer conversion of the ctype variable, meaning [int(frame_buffer)] is the odd required way to pass the frame buffer id to the function.

この機能も役に立つかもしれませんが、

def draw_texture(texture,offset,size,c):
glMatrixMode(GL_MODELVIEW)
glLoadIdentity() #Loads model matrix
glColor4fv(c)
glBegin(GL_QUADS)
glVertex2i(*offset) #Top Left
glVertex2i(offset[0],offset[1] + size[1]) #Bottom Left
glVertex2i(offset[0] + size[0],offset[1] + size[1]) #Bottom, Right
glVertex2i(offset[0] + size[0],offset[1]) #Top, Right
glEnd()
glColor4fv((1,1,1,1))
glBindTexture(GL_TEXTURE_2D, texture)
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0)
glVertex2i(*offset) #Top Left
glTexCoord2f(0.0, 1.0)
glVertex2i(offset[0],offset[1] + size[1]) #Bottom Left
glTexCoord2f(1.0, 1.0)
glVertex2i(offset[0] + size[0],offset[1] + size[1]) #Bottom, Right
glTexCoord2f(1.0, 0.0)
glVertex2i(offset[0] + size[0],offset[1]) #Top, Right
glEnd()
4

1 に答える 1

2

あなたは射影行列を示していないので、それもアイデンティティだと思います。

  • OpenGL フレームバッファの原点は左上ではなく、左下です。
  • サイズの問題は、説明するのがより困難です。結局のところ、あなたの射影行列は何ですか?
  • また、テクスチャの使用方法を示していないため、「間違った」画像で何を見ているのかわかりません。

関連のないコメント:

  • フレームごとにフレームバッファを作成することは、正しい方法ではありません。
  • 考えてみると、なぜフレームバッファを使用するのですか? あなたが求めているのは、フレーム バッファにブレンドすることだけだと思われますか? glEnable(GL_BLEND)それはうまくいきます。
于 2010-01-05T08:10:01.627 に答える