How can i load image?

I take this example in NeHe tutorial.But I can not load and write this image:


int LoadGLTextures()									// Load Bitmaps And Convert To Textures
{
	int Status=FALSE;									// Status Indicator

	AUX_RGBImageRec *TextureImage[1];					// Create Storage Space For The Texture

	memset(TextureImage,0,sizeof(void *)*1);           	// Set The Pointer To NULL

	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if (TextureImage[0]=LoadBMP("C:\\NeHe.bmp"))
	{
		Status=TRUE;									// Set The Status To TRUE

		glGenTextures( 1,&texture[0]);					// Create The Texture

		// Typical Texture Generation Using Data From The Bitmap
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	}

	if (TextureImage[0])									// If Texture Exists
	{
		if (TextureImage[0]->data)							// If Texture Image Exists
		{
///////////////////////////////////////////////////////////	////////////////////////////////	
   	free(TextureImage[0]->data);                            // Free The Texture Image Memory 
		}

		free(TextureImage[0]);								// Free The Image Structure
	}

	return Status;										// Return The Status
}

Thanks for all ur help.My OS is Windows and my ide Dev-C++

Can i do it with fread and fwrite binary read and write?

AUX is old. Don’t use it.

If you don’t know how to read a bmp file, then use a library
http://www.opengl.org/wiki/Related_toolkits_and_APIs#Image_and_Texture_Libraries

Thank u for ur exegesis.I elected to use SOIL.And i write these code:


#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <SOIL.h>

GLfloat angle = 0.0;       // Current turn angle.
GLfloat angle_step = 0.1;  // How much the angle changes between frames.
GLfloat angle_step2 = 0.1;
GLfloat change = 0.1;      // How much angle_step changes when arrows pressed.
GLuint texture[1];

GLfloat vertices[][3] =
  {  {1.0, 1.0, 0.0},
     {1.5, 1.0, 0.0},
     {1.5, -1.0, 0.0},
     {1.0, -1.0, 0.0},
     {1.5, 0.5, 0.0},
     {-1.5, 0.5, 0.0},
     {-1.5, 1.0, 0.0},
     {-1.0, 1.0, 0.0},
     {-1.0, -1.0, 0.0},
     {-1.5, -1.0, 0.0},
     {-1.5, -0.5, 0.0},
     {1.5, -0.5, 0.0},
     {-1.5, 1.0, -0.25},
     {1.5, 1.0, -0.25},
     {-0.75, 0.25, -2.0},
     {0.75, 0.25, -2.0},
     {-0.75, -1.0, -2.0},
     {0.75, -1.0, -2.0},
     {1.5, 1.0, -0.25},
     {1.5, -1.0, -0.25},
     {-1.5, -1.0, -0.25},
     {-1.5, 1.0, -0.25},
     {-1.0, 0.5, -0.2},
     {-1.0, -0.5, -0.2},
     {1.0, -0.5, -0.2},
     {1.0, 0.5, -0.2},
     {-1.25, -1.0, 0.5},
     {1.25, -1.0, 0.5},
     {1.25, -1.0, 1.5},
     {-1.25, -1.0, 1.5}

     };
     
GLfloat colors[][3] =
  {  {1.0, 1.0, 1.0},
     {0.0, 0.0, 0.0},
  };

  FILE *File=NULL;                           // File Handle

 



int LoadGLTextures()                           // Load Bitmaps And Convert To Textures
{
  int Status=FALSE;                           // Status Indicator

               // Create Storage Space For The Texture

                // Set The Pointer To NULL
texture[1] = SOIL_load_OGL_texture
	(
		"C:\\NeHe.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
	);
	
	if( 0 == texture[1] )
{
	printf( "SOIL loading error: '%s'
", SOIL_last_result() );
}

  // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
  if ( texture[1] = SOIL_load_OGL_texture
	(
		"C:\\NeHe.png",
		SOIL_LOAD_AUTO,
		SOIL_CREATE_NEW_ID,
		SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
	))
  {
     Status=TRUE;                           // Set The Status To TRUE

     glGenTextures(1, &texture[0]);               // Create The Texture

     // Typical Texture Generation Using Data From The Bitmap
     glBindTexture(GL_TEXTURE_2D, texture[0]);
    
     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  }

 

                           // Return The Status
 


void init(void)
{
  glClearColor(0.0, 0.0, 0.5, 1.0);
  
  /*if (!LoadGLTextures())                        // Jump To Texture Loading Routine ( NEW )
  {
     return FALSE;                           // If Texture Didn't Load Return FALSE
  }

  glEnable(GL_TEXTURE_2D);*/
}

void face4(int v0, int v1, int v2, int v3, int c)
  /* Render face with 4 vertices v1,v2,v3,v4 and colour c. */
{
  glColor3fv(colors[c]);
  glBegin(GL_POLYGON);
     glVertex3fv(vertices[v0]);
     glVertex3fv(vertices[v1]);
     glVertex3fv(vertices[v2]);
     glVertex3fv(vertices[v3]);
  glEnd();
}

void cable(int x1, int y1, int z1, int x2, int y2, int z2)
{
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex3f((x1),(y1),(z1));
glVertex3f((x2),(y2),(z2));
glEnd();
}



void comp(int v0, int v1, int v2)
/*render a computer at location v0,v1,v2 */
{ glTranslatef(v0, v1, v2);

  face4(0,1,2,3,0);
  face4(1,4,5,6,0);
  face4(6,7,8,9,0);
  face4(9,10,11,2,0);
  face4(6,12,13,1,0);
  face4(13,12,14,15,0);
  face4(15,14,16,17,0);
  face4(1,18,19,2,0);
  face4(6,9,20,21,0);
  face4(21,14,16,20,0);
  face4(18,15,17,19,0);
  face4(20,19,17,16,0);
  face4(22,23,24,25,1);
  face4(26,27,28,29,0);

   }


void network(int x, int y, int z)
{
    glTranslatef(x, y , z);

    glPushMatrix();
  glScalef(0.25, 0.25, 0.25);

  glPushMatrix();
  glTranslatef(-7.0, 0.0, -7.0);
  glRotatef(45.0, 0.0, 1.0, 0.0);
  comp(0,0,0);
  glPopMatrix();

  glPushMatrix();
  glTranslatef(-7.0, 0.0, 7.0);
  glRotatef(135.0, 0.0, 1.0, 0.0);
  comp(0,0,0);
  glPopMatrix();

 glPushMatrix();
  glTranslatef(7.0, 0.0, 7.0);
  glRotatef(-135.0, 0.0, 1.0, 0.0);
  comp(0,0,0);
  glPopMatrix();

  glPushMatrix();
  glTranslatef(7.0, 0.0, -7.0);
  glRotatef(-45.0, 0.0, 1.0, 0.0);
  comp(0,0,0);
  glPopMatrix();

  glPushMatrix();
  glLineWidth(5.0);
  cable(8,-0.1,-8,8,-0.1,8);
  cable(-8,-0.1,-8,-8,-0.1,8);
  cable(8,-0.1,-8,-8,-0.1,-8);
  cable(8,-0.1,8,-8,-0.1,8);
  glPopMatrix();

  glPopMatrix();

}void lan(void)
{  glPushMatrix();

  glTranslatef(-10.0, 0.0, 0.0);
  glRotatef(angle, 0.0, 1.0, 0.0);
  glScalef(1.5, 1.5, 1.5);
  network(0,0,0);
  glPopMatrix();
}

void wan(void)
{
  glTranslatef(-12.5, 0.0, 0.0);
  glPushMatrix();
  glScalef(0.5, 0.5, 0.5);

  glPushMatrix();
  network(10,0,-5);
  glPopMatrix();

  glPushMatrix();
  network(10,0,-10);
  glPopMatrix();

  glPushMatrix();
  network(15,0,-5);
  glPopMatrix();

  glPushMatrix();
  network(15,0,-10);
  glPopMatrix();

  glPushMatrix();
  network(15,0,10);
  glPopMatrix();

  glPushMatrix();
  network(15,0,15);
  glPopMatrix();

  glPushMatrix();
  network(10,0,10);
  glPopMatrix();

  glPushMatrix();
  network(10,0,15);
  glPopMatrix();

  glPushMatrix();
  network(30,0,10);
  glPopMatrix();

  glPushMatrix();
  network(30,0,15);
  glPopMatrix();

  glPushMatrix();
  network(35,0,10);
  glPopMatrix();

  glPushMatrix();
  network(35,0,15);
  glPopMatrix();

   glPushMatrix();
  network(30,0,-5);
  glPopMatrix();

  glPushMatrix();
  network(30,0,-10);
  glPopMatrix();

  glPushMatrix();
  network(35,0,-5);
  glPopMatrix();

  glPushMatrix();
  network(35,0,-10);
  glPopMatrix();

  glPushMatrix();
  glLineWidth(5.0);
  cable(10,-0.1,-3,10,-0.1,8);
  cable(17,-0.1,-10,28,-0.1,-10);
  cable(17,-0.1,15,28,-0.1,15);
  glPopMatrix();

  glPopMatrix();
}
void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(100.0, 1.4, 5.0, 50.0);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glPushMatrix();
  glTranslatef(0.0, 0.0, -5.0);
//Need to combine bmp texture to this polygon!
  /*glBindTexture(GL_TEXTURE_2D, texture[0]);*/
  glBegin(GL_POLYGON);
     glVertex2f(8.0, -3.0);
     glVertex2f(-8.0, -3.0);
     glVertex2f(-8.0, -6.0);
     glVertex2f(8.0, -6.0);
  glEnd();
  glPopMatrix();

  gluLookAt(0.0, 5.0, 15.0, 3.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  /*glRotatef(angle, 0.0, 1.0, 0.0);*/

  glPushMatrix();
  lan();
  glPopMatrix();

  glPushMatrix();
  glTranslatef(12.5, 0.0, 0.0);
  glRotatef(angle, 0.0, 1.0, 0.0);
  wan();
  glPopMatrix();


  glutSwapBuffers();



}

void specialKeys(int key, int x, int y)
{
  if (key == GLUT_KEY_LEFT)
     angle_step = angle_step + change;
  else if (key == GLUT_KEY_RIGHT)
     angle_step = angle_step - change;
}

void keyboard(unsigned char code, int x, int y)
{
  if (code == ' ')
     angle_step = 0.0;
  else if (code == 27)
     exit(0);
}

void update(void)
{
  angle = angle + angle_step2;
  if (angle >= 360.0)
     angle = angle - 360.0;
  else if (angle < 0.0)
     angle = angle + 360.0;
  glutPostRedisplay();
}
void reshape(int w, int h)
{
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(40.0, (GLdouble)w/(GLdouble)h, 0.5, 20.0);
  glViewport(0, 0, (GLsizei)w, (GLsizei)h);
}

int main(int argc, char** argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
  glutInitWindowSize(1000,700);
  glutInitWindowPosition(12.5,10);
  glutCreateWindow("Square");
  init();
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutIdleFunc(update);
  glutSpecialFunc(specialKeys);
  glutKeyboardFunc(keyboard);
  glutMainLoop();
  return 0;
}

But i take this error:


 C:\Dev-Cpp\example.c In function `LoadGLTextures': 
380 C:\Dev-Cpp\example.c syntax error at end of input 
 C:\Dev-Cpp\Makefile.win [Build Error]  [opengldenemeresim2.o] Error 1 

You can too use the DevIL library

Here an simple example of using this library into a GLUT program that include a picture into another :



#include <GL/glut.h>    // Header File For The GLUT Library 
#include <GL/gl.h>	// Header File For The OpenGL32 Library
#include <GL/glu.h>	// Header File For The GLu32 Library
#include <unistd.h>     // Header file for sleeping.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <IL/il.h>
#include <string.h>
 
/* ascii code for the escape key */
#define ESCAPE 27

#define FALSE 0
#define TRUE 1

/* The number of our GLUT window */
int window; 


ILuint ilTexture, ilSubTexture;													
GLuint Textures[2];
int texture=0;
char *dataTexture, *dataSubTexture, *initialTexture;
int w,h, f,bpp;
int wsub,hsub, fsub, bppsub;

int subheight=100;

int  i , j, k;


void IncludeSubPicture()
{
// Include the subpicture into the original picture
  ilBindImage(ilTexture);
  ilSetPixels(0,0,0,w,h,1,fsub,IL_UNSIGNED_BYTE, initialTexture);
  ilSetPixels(0,0,0,wsub,subheight,1,fsub,IL_UNSIGNED_BYTE, dataSubTexture);
  printf("subheight=%d 
", subheight);

  glBindTexture(GL_TEXTURE_2D, Textures[0]);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, dataTexture);
}

void InitDevIL()
{

  glEnable(GL_TEXTURE_2D);
  glGenTextures(2,Textures);
  glBindTexture(GL_TEXTURE_2D, Textures[0]);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
  glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  glBindTexture(GL_TEXTURE_2D,Textures[1]);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
  glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  ilInit();

  // Load the big picture with DevIL 
  ilGenImages(1, &ilTexture);
  ilBindImage(ilTexture);
  if( ilLoadImage("test1.jpg") != 0)
     printf("ilLoadImage %s OK 
", "test1.jpg");
  else
     printf("ilLoadImage %s KO 
", "test1.jpg");
   dataTexture = ilGetData();
   w = ilGetInteger(IL_IMAGE_WIDTH);
   h = ilGetInteger(IL_IMAGE_HEIGHT);
   f = ilGetInteger(IL_IMAGE_FORMAT);
   bpp = ilGetInteger(IL_IMAGE_BPP);
   printf("ilGetData = %x w=%d, h=%d bpp=%d 
", dataTexture,w,h,bpp);
   initialTexture=malloc(w*h*bpp);
   memcpy(initialTexture,dataTexture,w*h*bpp);

  // Load the subpicture
  ilGenImages(1, &ilSubTexture);
  ilBindImage(ilSubTexture);
  if( ilLoadImage("test2.jpg") != 0)
     printf("ilLoadImage %s OK 
", "test2.jpg");
  else
     printf("ilLoadImage %s KO 
", "test2.jpg");  
  dataSubTexture = ilGetData();
  wsub = ilGetInteger(IL_IMAGE_WIDTH);  
  hsub = ilGetInteger(IL_IMAGE_HEIGHT);
  fsub = ilGetInteger(IL_IMAGE_FORMAT);
  bppsub = ilGetInteger(IL_IMAGE_BPP);
  printf("ilGetData = %x w=%d, h=%d bpp=%d 
", dataSubTexture,wsub,hsub,bppsub);

  IncludeSubPicture();
}   

void DrawTest()
{

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear The Buffers
  glLoadIdentity ();											// Reset The Matrix

  glPushMatrix();
  glBindTexture(GL_TEXTURE_2D, Textures[texture]);
 
    glBegin(GL_QUADS);
    	//glColor3f(0,1,0); 
	glTexCoord2i(1,0); 
	glVertex3f(-1,-1,-1);

    	//glColor3f(0,0,1); 
	glTexCoord2i(0,0); 
	glVertex3f(1,-1,-1);

    	//glColor3f(1,0,0); 
	glTexCoord2i(0,1); 
	glVertex3f(1,1,-1);
    	
	//glColor3f(1,0,0); 
	glTexCoord2i(1,1); 
	glVertex3f(-1,1,-1);
  glEnd();
 
  glPopMatrix();
	glutSwapBuffers();
 
}


/* A general OpenGL initialization function.  Sets all of the initial parameters. */
void InitGL(int Width, int Height)	        // We call this right after our OpenGL window is created.
{

  // Start Of User Initialization
  glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);			// Realy Nice perspective calculations
	
  glClearColor (0.7f, 0.7f, 0.7f, 0.0f);						// Light Grey Background
  glClearDepth (1.0f);										// Depth Buffer Setup

  InitDevIL();

}

/* The function called when our window is resized (which shouldn't happen, because we're fullscreen) */
void ReSizeGLScene(int Width, int Height)
{
  if (Height==0)				// Prevent A Divide By Zero If The Window Is Too Small
    Height=1;

  glViewport(0, 0, Width, Height);		// Reset The Current Viewport And Perspective Transformation

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
  glMatrixMode(GL_MODELVIEW);
}


void Deinitialize (void)										// Any User DeInitialization Goes Here
{
	glDeleteTextures (2, Textures);					// Delete The Shader Texture ( NEW )
}

/* The function called whenever a key is pressed. */
void keyPressed(unsigned char key, int x, int y) 
{
    /* avoid thrashing this procedure */
  usleep(100);

    /* If escape is pressed, kill everything. */

  switch (key) {    
    
    case ESCAPE: // kill everything.
	/* shut down our window */
	Deinitialize();
	glutDestroyWindow(window); 
	
	/* exit the program...normal termination. */
	exit(1);                   	
	break; // redundant.

   case 56 : subheight++; printf("suhbeight=%d 
",subheight); IncludeSubPicture(); break;
   case 50 : subheight--; printf("suhbeight=%d 
",subheight); IncludeSubPicture(); break;

    default:
      printf ("Key %d pressed. No action there yet.
", key);
      break;
    }
    
    glutPostRedisplay();
}

void specialKeyPressed(int key, int x, int y) 
{
    /* avoid thrashing this procedure */
    usleep(100);

    switch (key) {    

    case GLUT_KEY_UP: // decrease x rotation speed;
	subheight++;	
	break;

    case GLUT_KEY_DOWN: // increase x rotation speed;
	subheight--;	
	break;

    default:
	break;
    }	
}

int main(int argc, char **argv) 
{  
  /* Initialize GLUT state - glut will take any command line arguments that pertain to it or 
     X Windows - look at its documentation at http://reality.sgi.com/mjk/spec3/spec3.html */  
  glutInit(&argc, argv);  

  /* Select type of Display mode:   
     Double buffer 
     RGBA color
     Alpha components supported 
     Depth buffer */  
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);  

  /* get a 640 x 480 window */
  glutInitWindowSize(640, 480);  

  /* the window starts at the upper left corner of the screen */
  glutInitWindowPosition(0, 0);  

  /* Open a window */  
  window = glutCreateWindow("YLP : first test with DevIL");  

  /* Register the function to do all our OpenGL drawing. */
  glutDisplayFunc(&DrawTest);  


  /* Register the function called when our window is resized. */
  glutReshapeFunc(&ReSizeGLScene);

  /* Register the function called when the keyboard is pressed. */
  glutKeyboardFunc(&keyPressed);
  
  glutSpecialFunc(&specialKeyPressed);
  
/* Initialize our window. */
  InitGL(640, 480);
  
  /* Start Event Processing Engine */  
  glutMainLoop();  

  return 1;
}


(this load two files named test1.jpg and test2.jpg but you can very easily modify the InitDevIL func for to load anothers pictures files, use the 8 and 2 numerics keys for to make the subpicture more or less big)

On linux, you can compile it like this


  gcc testil.c -o testil -L/usr/X11R6/lib -lGL -lGLU -lglut -lIL

I tried this.I take these error:


68 C:\Dev-Cpp\ilexam.cpp invalid conversion from `ILubyte*' to `char*' 
74 C:\Dev-Cpp\ilexam.cpp invalid conversion from `void*' to `char*' 
84 C:\Dev-Cpp\ilexam.cpp invalid conversion from `ILubyte*' to `char*' 

And my OS is Windows.

Certainly a cast problem or something like this

line 68 dataTexture = ilGetData();
=> dataTexture = (char *) ilGetData();

line 74 initialTexture=malloc(whbpp);
=> initialTexture = (char ) malloc(wh*bpp);

line 84 dataSubTexture = ilGetData();
=> dataSubTexture = (char *) ilGetData();

I take il linker errors.
Can i solve this problem?
:


#include <GL/glut.h>    // Header File For The GLUT Library 
#include <GL/gl.h>	// Header File For The OpenGL32 Library
#include <GL/glu.h>	// Header File For The GLu32 Library
#include <unistd.h>     // Header file for sleeping.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <fstream>


#include <string.h>
 
/* ascii code for the escape key */
#define ESCAPE 27

#define FALSE 0
#define TRUE 1

/* The number of our GLUT window */
int window; 


											
GLuint Textures[2];
int texture=0;
char *dataTexture, *dataSubTexture, *initialTexture;
int w,h, f,bpp;
int wsub,hsub, fsub, bppsub;

int subheight=100;

int  i , j, k;

FILE *dosya;
void IncludeSubPicture()
{  
// Include the subpicture into the original picture
 
  printf("subheight=%d 
", subheight);

  glBindTexture(GL_TEXTURE_2D, Textures[0]);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, dataTexture);
}
char *a;
void InitDevIL()
{

  glEnable(GL_TEXTURE_2D);
  glGenTextures(2,Textures);
  glBindTexture(GL_TEXTURE_2D, Textures[0]);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
  glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  glBindTexture(GL_TEXTURE_2D,Textures[1]);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);	
  glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);


dosya=fopen("C:\\NeHe.bmp","rb");
Textures[2]=fread(a,sizeof(unsigned char),1,dosya);

  // Load the big picture with DevIL 
 
  if(Textures[2]==0)
     printf("ilLoadImage %s OK 
", "Nehe.jpg");
  else
     printf("ilLoadImage %s KO 
", "Nehe.jpg");
  
   
  
   initialTexture=(char*)malloc(w*h*bpp);
   memcpy(initialTexture,dataTexture,w*h*bpp);

  // Load the subpicture
 
  if( Textures[2] != 0)
     printf("ilLoadImage %s OK 
", "Nehe.jpg");
  else
     printf("ilLoadImage %s KO 
", "Nehe.jpg");  

 
  printf("ilGetData = %x w=%d, h=%d bpp=%d 
", dataSubTexture,wsub,hsub,bppsub);

  IncludeSubPicture();
}   

void DrawTest()
{

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear The Buffers
  glLoadIdentity ();											// Reset The Matrix

  glPushMatrix();
  glBindTexture(GL_TEXTURE_2D, Textures[texture]);
 
    glBegin(GL_QUADS);
    	//glColor3f(0,1,0); 
	glTexCoord2i(1,0); 
	glVertex3f(-1,-1,-1);

    	//glColor3f(0,0,1); 
	glTexCoord2i(0,0); 
	glVertex3f(1,-1,-1);

    	//glColor3f(1,0,0); 
	glTexCoord2i(0,1); 
	glVertex3f(1,1,-1);
    	
	//glColor3f(1,0,0); 
	glTexCoord2i(1,1); 
	glVertex3f(-1,1,-1);
  glEnd();
 
  glPopMatrix();
	glutSwapBuffers();
 
}


/* A general OpenGL initialization function.  Sets all of the initial parameters. */
void InitGL(int Width, int Height)	        // We call this right after our OpenGL window is created.
{

  // Start Of User Initialization
  glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);			// Realy Nice perspective calculations
	
  glClearColor (0.7f, 0.7f, 0.7f, 0.0f);						// Light Grey Background
  glClearDepth (1.0f);										// Depth Buffer Setup

  InitDevIL();

}

/* The function called when our window is resized (which shouldn't happen, because we're fullscreen) */
void ReSizeGLScene(int Width, int Height)
{
  if (Height==0)				// Prevent A Divide By Zero If The Window Is Too Small
    Height=1;

  glViewport(0, 0, Width, Height);		// Reset The Current Viewport And Perspective Transformation

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
  glMatrixMode(GL_MODELVIEW);
}


void Deinitialize (void)										// Any User DeInitialization Goes Here
{
	glDeleteTextures (2, Textures);					// Delete The Shader Texture ( NEW )
}

/* The function called whenever a key is pressed. */
void keyPressed(unsigned char key, int x, int y) 
{
    /* avoid thrashing this procedure */
  

    /* If escape is pressed, kill everything. */

  switch (key) {    
    
    case ESCAPE: // kill everything.
	/* shut down our window */
	Deinitialize();
	glutDestroyWindow(window); 
	
	/* exit the program...normal termination. */
	exit(1);                   	
	break; // redundant.

   case 56 : subheight++; printf("suhbeight=%d 
",subheight); IncludeSubPicture(); break;
   case 50 : subheight--; printf("suhbeight=%d 
",subheight); IncludeSubPicture(); break;

    default:
      printf ("Key %d pressed. No action there yet.
", key);
      break;
    }
    
    glutPostRedisplay();
}

void specialKeyPressed(int key, int x, int y) 
{
    /* avoid thrashing this procedure */
  

    switch (key) {    

    case GLUT_KEY_UP: // decrease x rotation speed;
	subheight++;	
	break;

    case GLUT_KEY_DOWN: // increase x rotation speed;
	subheight--;	
	break;

    default:
	break;
    }	
}

int main(int argc, char **argv) 
{  
  /* Initialize GLUT state - glut will take any command line arguments that pertain to it or 
     X Windows - look at its documentation at http://reality.sgi.com/mjk/spec3/spec3.html */  
  glutInit(&argc, argv);  

  /* Select type of Display mode:   
     Double buffer 
     RGBA color
     Alpha components supported 
     Depth buffer */  
  glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);  

  /* get a 640 x 480 window */
  glutInitWindowSize(640, 480);  

  /* the window starts at the upper left corner of the screen */
  glutInitWindowPosition(0, 0);  

  /* Open a window */  
  window = glutCreateWindow("YLP : first test with DevIL");  

  /* Register the function to do all our OpenGL drawing. */
  glutDisplayFunc(&DrawTest);  


  /* Register the function called when our window is resized. */
  glutReshapeFunc(&ReSizeGLScene);

  /* Register the function called when the keyboard is pressed. */
  glutKeyboardFunc(&keyPressed);
  
  glutSpecialFunc(&specialKeyPressed);
  
/* Initialize our window. */
  InitGL(640, 480);
  
  /* Start Event Processing Engine */  
  glutMainLoop();  

  return 1;
}