1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
GLuint MFEAlterableTexture::Create(unsigned int width, unsigned int height)
{
this->width = width;
this->height = height;
unsigned int* data;
data = (GLuint *)calloc( 1, ((width * height)* 4 * sizeof(GLuint)) );
// ZeroMemory(data,((width * height)* 4 * sizeof(unsigned int)))
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
free( data );
return texture_id;
}
void MFEAlterableTexture::startRendering()
{
glViewport(0,0,width,height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.001f,50.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void MFEAlterableTexture::stopRendering()
{
// glEnable(GL_ALPHA_TEST);
// glAlphaFunc(GL_EQUAL, 1);
glBindTexture(GL_TEXTURE_2D, texture_id);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, width, height, 0);
// glDisable(GL_ALPHA_TEST);
glViewport(0, 0, 1024, 768);
} |
Partager