I have a little modified the source for to can see more precisely the 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 <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;
}
(it use the numerics 8 and 2 keys for to change the subpicture height)
=> in first view, textures seem zoomed …