2017-07-12 5 views
-2

Ich möchte texturierte Quad zeichnen, aber Textur ändert sich jeden Frame. Meine Textur ist 128x128 rgb-Array. Ich speichere den RGB-Wert jedes Pixels in diesem Array und ändere dieses Array jedes Bild. Auch meine Fenstergröße ist 1024x1024. Ich möchte mein Pixel-Array Vollbild, also erstelle ich eine Textur und füge diese Textur zu einem Full-Size-Quad hinzu. Wie kann ich das erreichen?OpenGL Rendering dynamische strukturierte Quad

Antwort

1
GLuint texID; 

void initphase() 
{ 
    /* create texture object */ 
    glGenTextures(1, &texID) 
    /* bind texture and allocate storage */ 
    glBindTexture(GL_TEXTURE_2D, texID); 
    glTexImage2D(GL_TEXTURE_2D, 
     …, 
     NULL /* just initialize */ 
    ); 
    /* alternative: 
    * Use glTexStorage instead of glTexImage. 
    * Requires a few changed in how texture is used though */ 

    /* set parameters like filtering mode, and such */ 
    glTexParameteri(…); 
} 

void player() 
{ 
    while(playing){ 
     glClear(…); 
     glViewport(…); 

     /* draw other stuff */ 

     glBindTexture(GL_TEXTURE_2D, texID); 
     /* copy image to texture */ 
     glTexSubImage2D(GL_TEXTURE_2D, 0, …, image_data); 
     if(using_shaders){ 
      glUseProgram(…); 
      setup_modelview_and_projection_uniforms(); 
     } else { 
      glEnable(GL_TEXTURE_2D); 
      setup_modelview_and_projection_matrices(); 
     } 
     glDraw…(…); /* draw quad */ 

     /* draw other stuff */ 
     swap_buffers(); 
    } 
}