how to decompress jpeg image by libjpeg-library

Hi Everyone,
i am new to openGL.

My question is :

How to decompress jpeg image by using libjpeg-library ? after getting decompressed image, i have to place it on object(like cube or Cylinder) using openGL(C/C++). i must use libjpeg library only.

Please give solution for my question.

http://www.opengl.org/wiki/Texture_Mapping

Hi,
thank you very much for your reply.

I referred the material which is there in  above link.

The above link shows how to do texture mapping, but i need to decompress jpeg image and that image(decompressed)is placed in buffer and than i have to place it on object…

Please help me…

Advance Thanks…

Then this is a libjpeg question, not much to do with opengl itself.
http://apodeline.free.fr/DOC/libjpeg/libjpeg.html

For an example code take a look at Section: “Texture Cooridinate Effects”. The function “load_texture” in main.c will give an example of how to use libjpeg.

Hi,
Thank you Very much for Both.

I go through the above links, they are very good sites to explain about libjpeg-library for decompression and Texture-mapping.

I have modified Texture coordinate program for my usage which is given below. The code below compiling without any error message, but the think is not displaying output on the window, please help me to get cylinders with different textures from the below code.

CODE :

#include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <jpeglib.h>
#include <jerror.h>

#define NUM_TEXTURES 10

typedef struct
{
char * name;
int format;
unsigned int size;
} texture_info_t;

static GLuint textures[NUM_TEXTURES];

static int left_click = GLUT_UP;
static int right_click = GLUT_UP;
static int xold;
static int yold;
static float rotate_x = 30;
static float rotate_y = 15;
static float translate_x = 0;
static float translate_y = 0;
static float plane_xy[3] = {1, 0, 0};
static float plane_yz[3] = {0, 0, 1};

GLfloat gAngle = 0.0;
GLUquadricObj *IDquadric;
int load_texture (const char * filename,
unsigned char * dest,
const int format,
const unsigned int size)
{
FILE *fd;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
unsigned char * line;

cinfo.err = jpeg_std_error (&jerr);
jpeg_create_decompress (&cinfo);

if (0 == (fd = fopen(filename, “rb”)))
return 1;

jpeg_stdio_src (&cinfo, fd);
jpeg_read_header (&cinfo, TRUE);
if ((cinfo.image_width != size) || (cinfo.image_height != size))
return 1;

if (GL_RGB == format)
{
if (cinfo.out_color_space == JCS_GRAYSCALE)
return 1;
}
else
if (cinfo.out_color_space != JCS_GRAYSCALE)
return 1;

jpeg_start_decompress (&cinfo);

while (cinfo.output_scanline < cinfo.output_height)
{
line = dest +
(GL_RGB == format ? 3 * size : size) * cinfo.output_scanline;
jpeg_read_scanlines (&cinfo, &line, 1);
}
jpeg_finish_decompress (&cinfo);
jpeg_destroy_decompress (&cinfo);
return 0;
}

void draw_cylinder()
{
glPushMatrix();
glTranslatef (translate_x, 0, translate_y);
glRotatef(90,1.,1.,0.);
gluCylinder(IDquadric,10.0f,10.0f,10.0f,32,32);
glPopMatrix();
}

void timer(int value)
{
const int desiredFPS=120;
glutTimerFunc(1000/desiredFPS, timer, ++value);
GLfloat dt = 1./desiredFPS;

gAngle += dt*360./8.;

glutPostRedisplay();
}

void DisplayFunc (void)
{
glMatrixMode (GL_TEXTURE);
glLoadIdentity ();
glScalef (1, -1, 1);
glMatrixMode (GL_MODELVIEW);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glTranslatef (0, 0, -10.);
glRotatef (rotate_y, 1, 0, 0);
glRotatef (rotate_x, 0, 1, 0);
glEnable (GL_TEXTURE_GEN_S);
glEnable (GL_TEXTURE_GEN_T);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture (GL_TEXTURE_2D, textures[0]);
glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv (GL_S, GL_EYE_PLANE, plane_xy);
glTexGenfv (GL_T, GL_EYE_PLANE, plane_yz);
glPushMatrix();
glTranslatef(-1,-1,0);
draw_cylinder();
glPopMatrix();
glBindTexture (GL_TEXTURE_2D, textures[1]);
glPushMatrix ();
glLoadIdentity ();
glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv (GL_S, GL_EYE_PLANE, plane_yz);
glTexGenfv (GL_T, GL_EYE_PLANE, plane_yz);
glPopMatrix ();
glPushMatrix();
glTranslatef(0,-1,0);
draw_cylinder();
glPopMatrix();
glBindTexture (GL_TEXTURE_2D, textures[1]);
glTexGenfv (GL_S, GL_EYE_PLANE, plane_xy);
glTexGenfv (GL_T, GL_EYE_PLANE, plane_yz);
glPushMatrix();
glTranslatef(1,-1,0);
draw_cylinder();
glPopMatrix();
glBindTexture (GL_TEXTURE_2D, textures[2]);
glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glPushMatrix();
glTranslatef(-1,0,0);
draw_cylinder();
glPopMatrix();
glBindTexture (GL_TEXTURE_2D, textures[3]);
glPushMatrix();
glTranslatef(0,0,0);
draw_cylinder();
glPopMatrix();
glBindTexture (GL_TEXTURE_2D, textures[4]);
glPushMatrix();
glTranslatef(1,0,0);
draw_cylinder();
glPopMatrix();
glBindTexture (GL_TEXTURE_2D, textures[5]);
glPushMatrix();
glTranslatef(0,1,0);
draw_cylinder();
glPopMatrix();
glBindTexture (GL_TEXTURE_2D, textures[6]);
glPushMatrix();
glTranslatef(-1,1,0);

draw_cylinder();
glPopMatrix();
glBindTexture (GL_TEXTURE_2D, textures[7]);

glColor3f (1, 0.7, 0);
glPushMatrix();
glTranslatef(0,-1,0);
draw_cylinder();
glPopMatrix();
glFlush ();
glutSwapBuffers ();
}

void ReshapeFunc (int width, int height)
{
glMatrixMode(GL_PROJECTION);

glLoadIdentity ();
gluPerspective (20, width / (float) height, 5, 15);
glViewport (0, 0, width, height);

glMatrixMode(GL_MODELVIEW);
glutPostRedisplay();
}

void cleanupQuadric(void)
{
gluDeleteQuadric(IDquadric);
printf( "cleanupQuadric completed
" );
}

void init() {
glClearColor(0.0, 0.0, 0.0, 0.0);

IDquadric=gluNewQuadric();
gluQuadricNormals(IDquadric, GLU_SMOOTH);
gluQuadricTexture(IDquadric, GL_TRUE);
atexit(cleanupQuadric);

GLdouble Vol = 101.8;
GLdouble Left=-Vol;
GLdouble Right=Vol;
GLdouble Bottom=-Vol;
GLdouble Top=Vol;
GLdouble Near=0;
GLdouble Far=2
Vol;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(Left, Right, Bottom, Top, Near, Far);

GLdouble eyeX=0;
GLdouble eyeY=0;
GLdouble eyeZ=-100+Vol;
GLdouble centerX=0;
GLdouble centerY=0;
GLdouble centerZ=-100;
GLdouble upX=0;
GLdouble upY=1;
GLdouble upZ=0;

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyeX,eyeY,eyeZ,
centerX,centerY,centerZ,
upX,upY,upZ);
}

void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}
}

int main(int argc, char** argv) {

unsigned char texture[NUM_TEXTURES][3 * 64 * 64];
unsigned int i;
static texture_info_t textures_info[] =
{
{ “marble.jpg”, GL_RGB, 64},
{ “chess.jpg”, GL_LUMINANCE, 64},
{ “chrome.jpg”, GL_RGB, 64},
{ “mercedes.jpg”, GL_RGB, 64},
{ “satin.jpg”, GL_RGB, 64},
{ “outline.jpg”, GL_LUMINANCE, 64},
{ “gold.jpg”, GL_RGB, 64},
{ “glass.jpg”, GL_ALPHA, 64},
{ 0, 0, 0}
};
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutCreateWindow (“Texture gen”);
glClearColor (0, 0, 0, 0);
glEnable (GL_DEPTH_TEST);
glEnable (GL_CULL_FACE);
glCullFace (GL_FRONT);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable (GL_TEXTURE_2D);
glGenTextures (NUM_TEXTURES, textures);
for (i = 0; textures_info[i].name != 0; ++i)
{
if (load_texture (textures_info[i].name,
texture[i],
textures_info[i].format,
textures_info[i].size) != 0)
return 1;

  glBindTexture (GL_TEXTURE_2D, textures[i]);
  gluBuild2DMipmaps (GL_TEXTURE_2D, textures_info[i].format,
                     textures_info[i].size, textures_info[i].size,
                     textures_info[i].format,
                     GL_UNSIGNED_BYTE,  texture[i]);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

}
glutDisplayFunc (&DisplayFunc);
glutReshapeFunc (&ReshapeFunc);
glutTimerFunc(0,timer,0);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

I am trying to place different textures on different cylinders.

Please Guide me From this problem.

Any answer is appreciated.

you need to add init() call before calling glutMainLoop(). And your Reshape function is writing PROJECTION and MODELVIEW matrices that don’t “lookat” your objects. They are set in init() so just remove them from ReshapFunc().


void ReshapeFunc (int width, int height)
{
	glViewport (0, 0, width, height);
}

and in main ... add init()

  init();
  glutDisplayFunc (&DisplayFunc);
  glutReshapeFunc (&ReshapeFunc);


Hi,

Very very Thanks.

As i added above details in my code.
Now it’s displaying single Cylinder with all images on that.

One more is if i use jpeg images whose size more that 4kbytes means it will not displaying the window.
I downloaded some images whose size is more that 500kbytes. if i try to place these images, it’s not displaying window.

One more doubt about below code.

Code :

   static texture_info_t textures_info[] =
{
  { "marble.jpg", GL_RGB, 64},
  { "chess.jpg", GL_LUMINANCE, 64},
  { "chrome.jpg", GL_RGB, 64},
  { "mercedes.jpg", GL_RGB, 64},
  { "satin.jpg", GL_RGB, 64},
  { "outline.jpg", GL_LUMINANCE, 64},
  { "gold.jpg", GL_RGB, 64},
  { "glass.jpg", GL_ALPHA, 64},
  { 0, 0, 0}
};

I know this is the initialization of images, but in the above code what is the use of

“GL_RGB, 64” & “GL_LUMINANCE, 64” what happen if i remove this.

Help me please,

Actually it is drawing four overlapping cylinders. Try changing the parameters to the gluCylinder function to smaller radii and you will see what I mean.


gluCylinder(IDquadric,0.2,0.2,10.0f,32,32);

I am not an expert with libjpeg – I use the DevIL Library.. The third parameter “64” has to match your actual image size – this code is expecting a 64x64 pixel image size! This might explain why you don’t see the images of >4K size. The parameters GL_RGB and GL_LUMINANCE etc tell what format each of the images are – the need to match what they are on the disk so you can’t remove/ignore them.

ps. This caveats (abut widthxheight and format specification) are one of the reasons why I use the DevIL library. But that is not the problem here. You just need to be careful how you use libjpeg and match the parameters to what the file images actually are.

Hi,

If you take a look at the load_texture function, you can see there it’s waiting for 4 arguments:

[ul][li]filename : the first element of the texture_info[]dest : the output buffer of the loading[]format : JPEG format of the file[*]size : width of the JPEG file (which is also the height since you must use square textures using this function)[/ul][/li]You should probably change the format and the size according to each JPEG file.

Hope this helps.

Best,

Hi,

Thank You so much for Both answers. which helps me a lot.
once again thanks.

From the code which is there in above post #268471.
Guide me, how to place all the images on the single Cylinder surface ?

please help me with this problem.

Any answer is appreciated

You should take a look to gluQuadricDrawstyle and gluQuadricTexture.

Hi,

Where should i include the above functions in post #268471.

The below two functions are used in the post #268471 :

gluQuadricNormals(IDquadric, GLU_SMOOTH);
gluQuadricTexture(IDquadric, GL_TRUE);

please guide me,

any answer will valuable…

Your code looks correct to me, but are the texture working correctly if you simply use them on quads or triangle ?

Hi All,

Thank you very much for showing interest.

The code which is there in my post #268471 is to display the images on different cylinders, Not to display all images on single Cylinder.

As per “Marshats” information i changed the code by reducing the radii of the cylinders after that i got different cylinders with different images on that. thank you “Marshats”.

But now i have got same doubt as what “Sindhu” asked in the last post.

Will it possible to display all images on the single Cylinder ?

if possible means how to allocate “size” for each image on the cylinder surface?

       please give the solution for above question.

any answer will valuable for me.

Thanking you.

If you take a look at http://pyopengl.sourceforge.net/documentation/manual/gluCylinder.3G.html you will be able to understand how the texture is taken in consideration when drawing the cylinder.
Thus, if you want to draw several images on one cylinder, you should construct one texture containing several images.

For example you could construct a texture with 0->0.5 is one image and 0.5->1 is another one. Finally, the cylinder will look like it has two textures even if it’s only one in the source code…

Hope this helps,

Hi,

Thank you very much.

As you told in post #268553 the above code is correct. but it is displaying many Cylinders with different images.
I want Single cylinder with many images on that. So i altered the code as below :

#include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <jpeglib.h>
#include <jerror.h>

#define NUM_TEXTURES 10

typedef struct
{
ILint h;
ILenum DestFormat;
ILenum DestType;
GLuint genID;
char * name;
int format;
unsigned int size;
} texture_info_t;

static GLuint textures[NUM_TEXTURES];

static int left_click = GLUT_UP;
static int right_click = GLUT_UP;
static int xold;
static int yold;
static float rotate_x = 30;
static float rotate_y = 15;
static float translate_x = 0;
static float translate_y = 0;
static float plane_xy[3] = {1, 0, 0};
static float plane_yz[3] = {0, 0, 1};

GLfloat gAngle = 0.0;
GLUquadricObj *IDquadric;
int load_texture (const char * filename,
unsigned char * dest,
const int format,
const unsigned int size)
{
FILE *fd;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
unsigned char * line;

cinfo.err = jpeg_std_error (&jerr);
jpeg_create_decompress (&cinfo);

if (0 == (fd = fopen(filename, “rb”)))
return 1;

jpeg_stdio_src (&cinfo, fd);
jpeg_read_header (&cinfo, TRUE);
if ((cinfo.image_width != size) || (cinfo.image_height != size))
return 1;

if (GL_RGB == format)
{
if (cinfo.out_color_space == JCS_GRAYSCALE)
return 1;
}
else
if (cinfo.out_color_space != JCS_GRAYSCALE)
return 1;

jpeg_start_decompress (&cinfo);

while (cinfo.output_scanline < cinfo.output_height)
{
line = dest +
(GL_RGB == format ? 3 * size : size) * cinfo.output_scanline;
jpeg_read_scanlines (&cinfo, &line, 1);
}
jpeg_finish_decompress (&cinfo);
jpeg_destroy_decompress (&cinfo);
return 0;
}

void timer(int value)
{
const int desiredFPS=120;
glutTimerFunc(1000/desiredFPS, timer, ++value);
GLfloat dt = 1./desiredFPS;

gAngle += dt*360./8.;

glutPostRedisplay();
}

void draw_cylinder()
{

glPushMatrix();
glTranslatef (translate_x, 0, translate_y);
glRotatef(gAngle,1.,1.,0.);
gluCylinder(IDquadric,10.0f,10.0f,10.0f,32,32);
glPopMatrix();
}

void DisplayFunc (void)
{
glMatrixMode (GL_TEXTURE);
glLoadIdentity ();
glScalef (1, -1, 1);
glMatrixMode (GL_MODELVIEW);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glTranslatef (0, 0, -10.);
glRotatef (rotate_y, 1, 0, 0);
glRotatef (rotate_x, 0, 1, 0);
glEnable (GL_TEXTURE_GEN_S);
glEnable (GL_TEXTURE_GEN_T);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture (GL_TEXTURE_2D, textures[0]);
glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGenfv (GL_S, GL_EYE_PLANE, plane_xy);
glTexGenfv (GL_T, GL_EYE_PLANE, plane_yz);
glPushMatrix();
glTranslatef(-1,-1,0);
draw_cylinder();
glPopMatrix();

glFlush ();
glutSwapBuffers ();

}

void ReshapeFunc (int width, int height)
{
glViewport (0, 0, width, height);

}

void cleanupQuadric(void)
{
gluDeleteQuadric(IDquadric);
printf( "cleanupQuadric completed
" );
}

void init() {
glClearColor(0.0, 0.0, 0.0, 0.0);

IDquadric=gluNewQuadric();

gluQuadricNormals(IDquadric, GLU_SMOOTH);
gluQuadricTexture(IDquadric, GL_TRUE);
atexit(cleanupQuadric);

GLdouble Vol = 101.8;
GLdouble Left=-Vol;
GLdouble Right=Vol;
GLdouble Bottom=-Vol;
GLdouble Top=Vol;
GLdouble Near=0;
GLdouble Far=2
Vol;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(Left, Right, Bottom, Top, Near, Far);

GLdouble eyeX=0;
GLdouble eyeY=0;
GLdouble eyeZ=-100+Vol;
GLdouble centerX=0;
GLdouble centerY=0;
GLdouble centerZ=-100;
GLdouble upX=0;
GLdouble upY=1;
GLdouble upZ=0;

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(eyeX,eyeY,eyeZ,
centerX,centerY,centerZ,
upX,upY,upZ);
}

void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
default:
break;
}
}

int main(int argc, char** argv) {

unsigned char texture[NUM_TEXTURES][3 * 64 * 64];
unsigned int i;
static texture_info_t textures_info[] =
{
/*
{ “marble.jpg”, GL_RGB, 64},
{ “chess.jpg”, GL_LUMINANCE, 64},
{ “chrome.jpg”, GL_RGB, 64},
{ “mercedes.jpg”, GL_RGB, 64},
{ “satin.jpg”, GL_RGB, 64},
{ “outline.jpg”, GL_LUMINANCE, 64},
{ “gold.jpg”, GL_RGB, 64}, */
{ “glass.jpg”, GL_ALPHA, 64},

{ 0, 0, 0}
};
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutCreateWindow (“Texture gen”);
glClearColor (0, 0, 0, 0);
glEnable (GL_DEPTH_TEST);
glEnable (GL_CULL_FACE);
glCullFace (GL_FRONT);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable (GL_TEXTURE_2D);
glGenTextures (NUM_TEXTURES, textures);
for (i = 0; textures_info[i].name != 0; ++i)
{
if (load_texture (textures_info[i].name,
texture[i],
textures_info[i].format,
textures_info[i].size) != 0)
return 1;

  glBindTexture (GL_TEXTURE_2D, textures[i]);
  gluBuild2DMipmaps (GL_TEXTURE_2D, textures_info[i].format,
                     textures_info[i].size, textures_info[i].size,
                     textures_info[i].format,
                     GL_UNSIGNED_BYTE,  texture[i]);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 }

    init();   

glutDisplayFunc (&DisplayFunc);

glutReshapeFunc (&ReshapeFunc);
glutTimerFunc(0,timer,0);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

This code generates Semi-cylinder, but not complete cylinder. please guide me to get complete cylinder.

i tried to load the images, but not getting how to do ?

i used the below function in init(), which you told in above post :

gluQuadricTexture(IDquadric, GL_TRUE);

Still it is not displaying images.

Help me please from this.

The semi-cylinder is due to culling glEnable (GL_CULL_FACE). And you need this with blending on otherwise the image shows a ghost of the backside. What you need to do is render to a blended rectanular texture then use that to map onto a culled cylinder (but now culling can be applied).

See Post268610 for an example. It does use Devil instead of libjpeg but that doesn’t change how to texture a quad first -> render to texture -> then use that to texture a culled cylinder.

Hi,

Thank you very much.

I replaced the above code using post268610. but i am getting the same output as previous i,e semi-cylinder.

please check the below code :

CODE :

#include <GL/gl.h>

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

#include <stdio.h>

#include <jpeglib.h>

#include <jerror.h>

#include <IL/il.h>
#include <GL/glext.h>
#define NUM_TEXTURES 10

GLfloat gAngle = 0.0;
GLUquadricObj *IDquadric;

GLuint gState = 0;

typedef struct
{
ILenum DestFormat;
ILenum DestType;
GLuint genID;
char * name;
int format;
unsigned int size;
} texture_info_t;

static GLuint textures[NUM_TEXTURES];

static int left_click = GLUT_UP;
static int right_click = GLUT_UP;
static int xold;
static int yold;
static float rotate_x = 30;
static float rotate_y = 15;
static float translate_x = 0;
static float translate_y = 0;
static float plane_xy[3] = {1, 0, 0};
static float plane_yz[3] = {0, 0, 1};

struct TextureHandle
{
ILubyte *p;
ILuint id;
ILint w;
ILint h;
ILenum DestFormat;
ILenum DestType;
GLuint genID;
};

struct TextureHandle logo;
struct TextureHandle logo2;
struct TextureHandle logoM;

int load_texture (const char * filename,unsigned char *
dest,const int format,const unsigned int size)
{
FILE *fd;

struct jpeg_decompress_struct cinfo;

struct jpeg_error_mgr jerr;

unsigned char * line;

cinfo.err = jpeg_std_error (&jerr);

jpeg_create_decompress (&cinfo);

if (0 == (fd = fopen(filename, “rb”)))

return 1;

jpeg_stdio_src (&cinfo, fd);

jpeg_read_header (&cinfo, TRUE);

if ((cinfo.image_width != size) || (cinfo.image_height !=
size))

return 1;

if (GL_RGB == format)
{

if (cinfo.out_color_space == JCS_GRAYSCALE)

 return 1;

}
else

if (cinfo.out_color_space != JCS_GRAYSCALE)

return 1;

jpeg_start_decompress (&cinfo);

while (cinfo.output_scanline < cinfo.output_height)
{

line = dest +
    (GL_RGB == format ? 3 * size : size) 
  • cinfo.output_scanline;

    jpeg_read_scanlines (&cinfo, &line, 1);
    

    }

jpeg_finish_decompress (&cinfo);

jpeg_destroy_decompress (&cinfo);

return 0;

}

void timer(int value)
{
const int desiredFPS=120;
glutTimerFunc(1000/desiredFPS, timer, ++value);
GLfloat dt = 1./desiredFPS;

gAngle += dt*360./8.;

glutPostRedisplay();
}

void draw_cylinder()
{
glPushMatrix();
glTranslatef(-5.,0,-100);
glRotatef(gAngle,1.,1.,0.);
gluCylinder(IDquadric,10.0f,10.0f,10.0f,32,32);
glPopMatrix();
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

if (gState) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR,GL_DST_COLOR);

glBlendColor(.5,.5,.5,.5); 

glBindTexture ( GL_TEXTURE_2D, logo.genID);
draw_cylinder();

glBindTexture ( GL_TEXTURE_2D, logo2.genID);
draw_cylinder();

glDisable(GL_BLEND);

} else {
glBindTexture ( GL_TEXTURE_2D, logoM.genID);
draw_cylinder();
}

glutSwapBuffers();
}

void CreateMultiTexture()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);

glViewport(0,0,logoM.w,logoM.h);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR,GL_DST_COLOR);

glBlendColor(.5,.5,.5,.5);

glBindTexture ( GL_TEXTURE_2D, logo.genID);
glBegin(GL_QUADS);
 glTexCoord2f(0,0); glVertex2f(-1,-1);  
 glTexCoord2f(1,0); glVertex2f( 1,-1);  
 glTexCoord2f(1,1); glVertex2f( 1, 1);  
 glTexCoord2f(0,1); glVertex2f(-1, 1);  
glEnd();

glBindTexture ( GL_TEXTURE_2D, logo2.genID);
glBegin(GL_QUADS);
 glTexCoord2f(0,0); glVertex2f(-1,-1);  
 glTexCoord2f(1,0); glVertex2f( 1,-1);  
 glTexCoord2f(1,1); glVertex2f( 1, 1);  
 glTexCoord2f(0,1); glVertex2f(-1, 1);  
glEnd();

glDisable(GL_BLEND);

glBindTexture(GL_TEXTURE_2D,logoM.genID);

glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, logoM.w,
logoM.h, 0);

glViewport(viewport[0], viewport[1], viewport[2] ,viewport
[3]);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();

glutSwapBuffers();

glutDisplayFunc(display);
}

void cleanupQuadric(void)
{
gluDeleteQuadric(IDquadric);
printf( "cleanupQuadric completed
" );
}

void init() {

glClearColor(0.0, 0.0, 0.0, 0.0);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

IDquadric=gluNewQuadric();

gluQuadricNormals(IDquadric, GLU_SMOOTH);

gluQuadricTexture(IDquadric, GL_TRUE);

atexit(cleanupQuadric);

GLdouble Vol = 10*1.8;

GLdouble Left=-Vol;

GLdouble Right=Vol;

GLdouble Bottom=-Vol;

GLdouble Top=Vol;

GLdouble Near=0;

GLdouble Far=2*Vol;

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glOrtho(Left, Right, Bottom, Top, Near, Far);

GLdouble eyeX=0;

GLdouble eyeY=0;

GLdouble eyeZ=-100+Vol;

GLdouble centerX=0;

GLdouble centerY=0;

GLdouble centerZ=-100;

GLdouble upX=0;

GLdouble upY=1;

GLdouble upZ=0;

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(eyeX,eyeY,eyeZ,
centerX,centerY,centerZ,
upX,upY,upZ);

ilInit();

glEnable (GL_TEXTURE_2D);

}

void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case 27:
exit(0);
break;
default:
gState++;
gState %= 2;
printf("%d
",gState);
break;
}
}

int main(int argc, char** argv)
{
unsigned char texture[NUM_TEXTURES][3 * 64 * 64];

unsigned int i;

static texture_info_t textures_info[] =
{{ “marble.jpg”,
GL_RGB, 64},

 { "chess.jpg", GL_LUMINANCE, 64},

{ “chrome.jpg”, GL_RGB, 64},

 { "mercedes.jpg", GL_RGB, 64},

  { "satin.jpg", GL_RGB, 64}, 

 { "outline.jpg", GL_LUMINANCE, 64},

	{ "gold.jpg", GL_RGB, 64}, 
  { "glass.jpg", GL_ALPHA, 64},

{ 0, 0, 0}
};

glutInit (&argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutInitWindowSize (500, 500);

glutCreateWindow (“Texture gen”);

glClearColor (0, 0, 0, 0);

glEnable (GL_DEPTH_TEST);

glEnable (GL_CULL_FACE);

glCullFace (GL_FRONT);

glEnable (GL_BLEND);

glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glEnable (GL_TEXTURE_2D);

glGenTextures (NUM_TEXTURES, textures);

for (i = 0; textures_info[i].name != 0; ++i)
{

if (load_texture (textures_info[i].name,texture[i],

textures_info[i].format,textures_info[i].size) != 0)

   return 1;


 glBindTexture (GL_TEXTURE_2D, textures[i]);


  gluBuild2DMipmaps (GL_TEXTURE_2D, textures_info

[i].format,

textures_info[i].size,
textures_info[i].size,

textures_info[i].format,

GL_UNSIGNED_BYTE, texture[i]);

  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 

GL_LINEAR);

glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 

GL_LINEAR);

 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, 

GL_REPEAT);

 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 

GL_REPEAT);

}

glutDisplayFunc (CreateMultiTexture);

glutTimerFunc(0,timer,0);

glutKeyboardFunc(keyboard);


     init();

    glutMainLoop();

     return 0;
   
 }

While compiling the above code it is generating the warnings.
and while running it shows the same as previous …

Guide me please.

What happens if you comment out the line “glEnable (GL_CULL_FACE);”?