我想绘制纹理四边形,但纹理每帧都在变化。我的纹理是128x128
rgb数组。我将每个像素的rgb值存储在该数组中,我每帧都在更改该数组。我的窗口大小也是1024x1024
。我希望我的像素阵列全屏,所以我创建一个纹理并将此纹理添加到一个全尺寸的四边形。我怎样才能做到这一点?
答案 0 :(得分: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();
}
}