hi.
i had draws a square . a very simple square with green color.
i want to put it into a picture .but i failed ,here is my code.
could you help me fix my mistake .thank you.
[b]
#include <GL/glut.h>
#include <stdlib.h>
#include “stdio.h”
#include “math.h”
#include “rgb.h”
RGBImageRec *earthImage = NULL;
GLuint texture;
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
earthImage = rgbImageLoad(“water2.bmp”);
if (earthImage == NULL)
{exit(1);}
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D,0,3,earthImage->sizeX,earthImage->sizeY,0,GL_RGB,GL_UNSIGNED_BYTE,earthImage->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
}
float x[4][2]={{-1,-1},{1,-1},{1,1},{-1,1}};
void display(void)
{
glEnable(GL_TEXTURE_2D);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTranslatef(0,0,-10);
glBindTexture(GL_TEXTURE_2D, texture);
glPushMatrix ();
glColor3f(0,1,0);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2fv(x[0]);
glTexCoord2f(1, 0);
glVertex2fv(x[1]);
glTexCoord2f(1.0f, 1.0f);
glVertex2fv(x[2]);
glTexCoord2f(0, 1.0f);
glVertex2fv(x[3]);
glEnd();
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0, (GLfloat) w/(GLfloat) h, 1, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
[/b]