,请大手们帮帮小弟,关键代码如下:
GLfloat vertices[4][2] = {
{ 0.0f, 1.0f},
{ 1.0f, 1.0f},
{ 0.0f, 0.0f},
{ 1.0f, 0.0f}
};GLfloat texture[4][2] = {
{ 0.0f, 1.0f},
{ 1.0f, 1.0f},
{ 0.0f, 0.0f},
{ 1.0f, 0.0f}
};
#define filename "E:/opengl/1.bmp"
static const char *str=filename;
static GLint imagewidth;
static GLint imageheight;
static GLint pixellength;
static GLubyte* pixeldata;void readpixel()
{
FILE *pFile=fopen(str,"rb");
if(pFile==0)
exit(0);
fseek(pFile,0x0012,SEEK_SET);
fread(&imagewidth,sizeof(imagewidth),1,pFile);
fread(&imageheight,sizeof(imageheight),1,pFile);
pixellength=imagewidth*3;
while(pixellength%4!=0)
++pixellength;
pixellength*=imageheight;
pixeldata=(GLubyte*)malloc(pixellength);
if(pixeldata==0)
exit(0);
fseek(pFile,54,SEEK_SET);
fread(pixeldata,pixellength,1,pFile);
fclose(pFile);
}
GLuint image_texture[1];
void fun()
{
        glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_SRC_COLOR);
glGenTextures(1, &image_texture[0]);
glBindTexture(GL_TEXTURE_2D, image_texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imagewidth, imageheight, 0, GL_RGB,
GL_UNSIGNED_BYTE, pixeldata);
}void RenderInit()
{
// Grab location of shader attributes.
locVertices = glGetAttribLocation(programHandle, "my_Vertex");
locColors   = glGetAttribLocation(programHandle, "my_Color");
// Transform Matrix is uniform for all vertices here.
locTransformMat = glGetUniformLocation(programHandle, "my_TransformMatrix"); glEnableVertexAttribArray(locVertices); glVertexAttribPointer(locVertices, 2, GL_FLOAT, GL_FALSE, 0, &vertices[0][0]);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, &texture[0][0]);
glUniformMatrix4fv(locTransformMat, 1, GL_FALSE, transformMatrix);
}// Actual rendering here.
void Render()
{
static float angle = 0; // Clear background.
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); // Set up rotation matrix rotating by angle around y axis.
transformMatrix[0] = transformMatrix[10] = (GLfloat)cos(angle);
transformMatrix[2] = (GLfloat)sin(angle);
transformMatrix[8] = -transformMatrix[2];
angle += 0.01f;
glUniformMatrix4fv(locTransformMat, 1, GL_FALSE, transformMatrix); glBindTexture(GL_TEXTURE_2D, image_texture[0]);
glDrawArrays(GL_TRIANGLES, 0, 4);
// flush all commands.
glFlush ();
// swap display with drawn surface.
vdkSwapEGL(&egl);
}
int main()
{
    //...
    readpixel();
    fun();
    RenderInit();
    Render();
    //...
}