Domanda

sto usando python ma OpenGL è praticamente fatto esattamente nello stesso modo come in qualsiasi altra lingua.

Il problema è che, quando si tenta di rendere un tessuto o una linea di trama per mezzo di un oggetto frame buffer, è reso capovolto, troppo piccolo in basso a sinistra. Molto strano. Ho queste immagini per dimostrare:

Questo è come appare,

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

Questo è come sembrava quando stavo usando pygame invece. Pygame è troppo lento, ho imparato. Il mio gioco sarebbe ingiocabile senza la velocità di OpenGL. Ignorare gli angoli curvi. Non ho ancora implementato quelli in OpenGL. Ho bisogno di risolvere questo problema prima.

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

Non sto usando la profondità.

Che cosa ha potuto causare questo comportamento irregolare. Ecco il codice (Le funzioni sono rientrati nel codice vero e proprio. Mostrano a destra), si possono trovare utili,

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.

Questa funzione può anche essere utile,

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()
È stato utile?

Soluzione

Non mostrare la tua matrice di proiezione, quindi darò per scontato che sia troppo identità.

    origine
  • OpenGL framebuffer è in basso a sinistra, non alto a sinistra.
  • Il problema dimensione è più difficile da spiegare. Qual è la sua matrice di proiezione, dopo tutto?
  • anche, non si mostra come utilizzare la texture, e non sono sicuro di quello che stiamo guardando nella vostra immagine "corretta".

Alcuni commenti non correlati:

  • creazione di un framebuffer ogni fotogramma non è il modo giusto per andare su di esso.
  • venire a pensarci, perché utilizzare framebuffer a tutti? sembra che l'unica cosa che stai dopo si mescola al frame buffer? glEnable(GL_BLEND) lo fa bene.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top