2017-07-12 2 views
-2

テクスチャ付きクワッドを描画したいが、テクスチャはすべてのフレームで変化する。私のテクスチャは128x128 rgbの配列です。私はその配列に各ピクセルのrgb値を格納し、私はそのフレームごとにその配列を変更しています。私のウィンドウサイズも1024x1024です。私はピクセル配列をフルスクリーンで表示したいので、テクスチャを作成してこのテクスチャをフルサイズのクワッドに追加します。どうすればこれを達成できますか?OpenGLレンダリングダイナミックテクスチャクワッド

答えて

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(); 
    } 
}