PDA

View Full Version : how to decompress jpeg image by libjpeg-library



Krishna12
12-07-2009, 04:30 AM
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.

ZbuffeR
12-07-2009, 05:34 AM
http://www.opengl.org/wiki/Texture_Mapping

Krishna12
12-08-2009, 05:02 AM
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..

ZbuffeR
12-08-2009, 05:56 AM
Then this is a libjpeg question, not much to do with opengl itself.
http://apodeline.free.fr/DOC/libjpeg/libjpeg.html

marshats
12-08-2009, 07:34 PM
For an example code take a look at Section: "Texture Cooridinate Effects" (http://zavie.free.fr/opengl/index.html.en). The function "load_texture" in main.c will give an example of how to use libjpeg.

Krishna12
12-09-2009, 03:04 AM
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 (&amp;jerr);
jpeg_create_decompress (&amp;cinfo);

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

jpeg_stdio_src (&amp;cinfo, fd);
jpeg_read_header (&amp;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 (&amp;cinfo);

while (cinfo.output_scanline < cinfo.output_height)
{
line = dest +
(GL_RGB == format ? 3 * size : size) * cinfo.output_scanline;
jpeg_read_scanlines (&amp;cinfo, &amp;line, 1);
}
jpeg_finish_decompress (&amp;cinfo);
jpeg_destroy_decompress (&amp;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\n" );
}

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 = 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);
}

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 (&amp;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 (&amp;DisplayFunc);
glutReshapeFunc (&amp;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.

marshats
12-09-2009, 09:08 PM
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 (&amp;DisplayFunc);
glutReshapeFunc (&amp;ReshapeFunc);

Krishna12
12-09-2009, 10:13 PM
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,

marshats
12-09-2009, 11:23 PM
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. (http://openil.sourceforge.net/about.php). 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.

Benoit
12-10-2009, 01:20 AM
...

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.



Hi,

If you take a look at the load_texture function, you can see there it's waiting for 4 arguments:
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)
You should probably change the format and the size according to each JPEG file.

Hope this helps.

Best,

Sindhu
12-10-2009, 03:17 AM
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

Benoit
12-10-2009, 03:22 AM
You should take a look to gluQuadricDrawstyle and gluQuadricTexture.

Sindhu
12-10-2009, 03:53 AM
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..

Benoit
12-10-2009, 04:59 AM
Your code looks correct to me, but are the texture working correctly if you simply use them on quads or triangle ?

Krishna12
12-10-2009, 05:54 AM
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.

Benoit
12-10-2009, 07:01 AM
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,

Krishna12
12-14-2009, 06:11 AM
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 (&amp;jerr);
jpeg_create_decompress (&amp;cinfo);

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

jpeg_stdio_src (&amp;cinfo, fd);
jpeg_read_header (&amp;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 (&amp;cinfo);

while (cinfo.output_scanline < cinfo.output_height)
{
line = dest +
(GL_RGB == format ? 3 * size : size) * cinfo.output_scanline;
jpeg_read_scanlines (&amp;cinfo, &amp;line, 1);
}
jpeg_finish_decompress (&amp;cinfo);
jpeg_destroy_decompress (&amp;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\n" );
}

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 = 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);
}

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 (&amp;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 (&amp;DisplayFunc);

glutReshapeFunc (&amp;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.

marshats
12-14-2009, 08:47 PM
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 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&amp;Number=268610#Post2686 10) 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.

Krishna12
12-15-2009, 12:10 AM
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 (&amp;jerr);

jpeg_create_decompress (&amp;cinfo);


if (0 == (fd = fopen(filename, "rb")))

return 1;


jpeg_stdio_src (&amp;cinfo, fd);

jpeg_read_header (&amp;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 (&amp;cinfo);


while (cinfo.output_scanline < cinfo.output_height)
{

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

jpeg_read_scanlines (&amp;cinfo, &amp;line, 1);

}

jpeg_finish_decompress (&amp;cinfo);

jpeg_destroy_decompress (&amp;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\n" );
}





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\n",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 (&amp;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.

marshats
12-15-2009, 09:48 AM
What happens if you comment out the line "glEnable (GL_CULL_FACE);"?

marshats
12-15-2009, 09:11 PM
You had errors because you didn't reconcile the other image loading code using Devil when you converted to your use of libjpeg. The following code runs but you have to have three new images: logo.jpg and logo2.jpg of size 64x64 and a blank.jpg of size 128x128. I don't claim this code is the best I just hacked your previous post until it worked ;) You will have to understand it an clean it up to your preference of coding style. Note I moved genID into the texture_info structure and consequently remove the textures[] array.



#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 20

GLfloat gAngle = 0.0;
GLUquadricObj *IDquadric;

GLuint gState = 0;

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

static texture_info_t textures_info[] =
{
{ "marble.jpg", GL_RGB, 64, 0 },
{ "chess.jpg", GL_LUMINANCE, 64, 0},
{ "chrome.jpg", GL_RGB, 64, 0},
{ "mercedes.jpg", GL_RGB, 64, 0},
{ "satin.jpg", GL_RGB, 64, 0},
{ "outline.jpg", GL_LUMINANCE, 64, 0},
{ "marble.jpg", GL_RGB, 64, 0},
{ "marble.jpg", GL_RGB, 64, 0},
{ "satin.jpg", GL_RGB, 64, 0},
{ "satin.jpg", GL_RGB, 64, 0}, //
{ "logo.jpg", GL_RGB, 64, 0}, // kludge to start at 10 for logo, logo2, blank
{ "logo2.jpg", GL_RGB, 64, 0},
{ "blank.jpg", GL_RGB, 128, 0},
{ NULL, 0, 0, 0}
};

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};

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 (&amp;jerr);

jpeg_create_decompress (&amp;cinfo);

if (0 == (fd = fopen(filename, "rb")))

return 1;

jpeg_stdio_src (&amp;cinfo, fd);

jpeg_read_header (&amp;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 (&amp;cinfo);

while (cinfo.output_scanline < cinfo.output_height)
{

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

jpeg_read_scanlines (&amp;cinfo, &amp;line, 1);

}

jpeg_finish_decompress (&amp;cinfo);

jpeg_destroy_decompress (&amp;cinfo);

fclose(fd);

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, textures_info[10].genID);
draw_cylinder();

glBindTexture ( GL_TEXTURE_2D, textures_info[11].genID);
draw_cylinder();

glDisable(GL_BLEND);
}
else
{
glBindTexture ( GL_TEXTURE_2D, textures_info[12].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,textures_info[12].size,textures_info[12].size);

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

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

glBindTexture ( GL_TEXTURE_2D, textures_info[10].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, textures_info[11].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,textures_info[12].genID);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, textures_info[12].size, textures_info[12].size, 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\n" );
}


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\n",gState);
break;
}
}


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

glutInit (&amp;argc, argv);
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutCreateWindow ("Texture gen");

glClearColor (0, 0, 0, 0);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glEnable (GL_TEXTURE_2D);

for (i = 0; textures_info[i].size != 0; ++i)
{
glGenTextures (1, &amp;textures_info[i].genID);

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_info[i].genID);

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);

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]);
}

glutDisplayFunc (CreateMultiTexture);
glutTimerFunc(0,timer,0);
glutKeyboardFunc(keyboard);

init();

glutMainLoop();

return 0;
}

Krishna12
12-15-2009, 10:14 PM
Hi,
Thank you for your hint,

The code generates the full cylinder, if i commented the line glEnable(GL_CULL_FACE);

One more is above code is not taking the images from the textures array.Even after i created logo, logo2 , blank images with size you specified.
and Output window with cylinder is also not Displaying.

What shall i do ?

please guide me.

marshats
12-16-2009, 08:40 AM
Are the new images log*.jpg and blank.jpg all black?

I cut and pasted the above code and recompiled it. If I had black images then nothing would show but otherwise the cylinder showed with logo*.jpg images (don't care about blank.jpg colors just that its size is 128x128) that were say copies marble.jpg.

Also you should see a textured square in the lower left corner of the screen (no cylinder will be visible) if you comment out the line "glutDisplayFunc(display);" at the end of CreateMultiTexture() function. Can you please confirm what you see?

Krishna12
12-17-2009, 06:00 AM
Hi,

Thanks a lot. I verified what you told in the above post.

I used the above code as it is, except textures_info[] array which i pasted below :

static texture_info_t textures_info[] =
{
// { "/localhome/user/Temp/sample/marble.jpg", GL_RGB, 64, 0 },
// { "/localhome/user/Temp/sample/chess.jpg", GL_LUMINANCE, 64, 0},

// { "/localhome/user/Temp/sample/chrome.jpg", GL_RGB, 64, 0},
// { "/localhome/user/Temp/sample/mercedes.jpg", GL_RGB, 64, 0},
// { "/localhome/user/Temp/sample/satin.jpg", GL_RGB, 64, 0},
// { "/localhome/user/Temp/sample/outline.jpg", GL_LUMINANCE, 64, 0},

// { "/localhome/user/Temp/sample/marble.jpg", GL_RGB, 64, 0},
// { "/localhome/user/Temp/sample/marble.jpg", GL_RGB, 64, 0},
// { "/localhome/user/Temp/sample/satin.jpg", GL_RGB, 64, 0},
// { "/localhome/user/Temp/sample/satin.jpg", GL_RGB, 64, 0},
{ "/localhome/user/Temp/sample/logo.jpg", GL_RGB, 64, 0},
{ "/localhome/user/Temp/sample/logo2.jpg", GL_RGB, 64, 0},

{ "/localhome/user/Temp/sample/blank12.jpg", GL_RGB, 128, 0},
{ NULL, 0, 0, 0}
};


where logo.jpg & logo2.jpg are images not blank, where as blank12.jpg is a blank image.
if i comment the lines which i show in this post. displayed cylinder only, no images on that,
if i remove the comments in the above lines, its not showing output window.

i have all the images in the folder

"/localhome/user/Temp/sample/" folder. So i gave that path.


What will be the problem ?

Even if i remove all the comments which are there in the above lines and commented the below line :
glutDisplayFunc(display)

Then also it's not displaying any window.

please guide me.

marshats
12-17-2009, 07:56 AM
In void CreateMultiTexture() there are hardcoded references


textures_info[10].genID
textures_info[11].genID
textures_info[12].size
etc

so that explains why you must _not_ comment out the lines in
static texture_info_t textures_info[] for now.

The filename strings as "/localhome/user/Temp/sample/marble.jpg" with forward slashes works on linux/mingw but probably not windows -- what os are you on? To remove any doubt, just leave that code alone and copy all those image files into the same place where the executable is created to avoid the path specification for now.

The fact that it is not displaying a window at all (case with comments removed) -- you have exit on failure code in load_texture() -- I suspect that one of your jpegs is not loading or loading with a failure hence causes the code to exit before a window can be drawn. I suggest modifying in main


if (load_texture (textures_info[i].name,texture[i],textures_info[i].format,textures_info[i].size) != 0)
{
printf("failed to load an image %s",textures_info[i].name,texture[i] );
return 1;
}
printf("successs: loaded %s",textures_info[i].name,texture[i]);


ps I will be out of the office for the next two weeks on vacation. Sorry I won't be able to help during that time.

Krishna12
12-21-2009, 02:47 AM
Hi,

Thank you so much.

I replaced lines in main program(where the function called loadtexture()) with the above lines .
so after that i am getting messages like :




successs: loaded marble.jpgsuccesss: loaded chess.jpgsuccesss: loaded blank12.jpg1
cleanupQuadric completed
user@lxdevenv:~/Temp/sample$



The output is cylinder with no images on that.

i dint get the code which you posted :




textures_info[10].genID
textures_info[11].genID
textures_info[12].size
etc


What this indicates ?


please help me from this ..

Krishna12
01-04-2010, 06:55 AM
Hi,

Could you help me on this .please help me from this problem .


Thanking You.

marshats
01-05-2010, 07:41 PM
The comment on the 10,11,12 indexes is just a temporary kludge to not alter your existing code -- I don't use the first 0-9 references but if you comment any of them out then for instance what I expect to be [10] becomes mis-defined as a lower index number -- basically do not comment out any of the "static texture_info_t textures_info[] = ..." block for now while debugging.

It is really difficult to detect the problem without having your exact textures -- I had a similar post to this thread which requests how to share files in this forum -- please read Post269741 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&amp;Number=269741#Post2697 41) so you can share your exact texture files. I really can't help much more without having the same exact files as you -- the code runs fine on my machine but yours doesn't and the only difference is the textures actually used.

Krishna12
01-06-2010, 02:37 AM
Hi,

Thank you very much,


I am sending link where the program is :

http://uploading.com/files/44a2e4mf/recglut.c/

and the images are shared in the below link :

http://img514.imageshack.us/gal.php?g=mercedesgk.jpg

i am not getting the above process.
please help me to clear the problem.


Thankinh you.

marshats
01-06-2010, 07:34 AM
The image files downloaded are


blankcr.jpg chessx.jpg chromecd.jpg golds.jpg marblel.jpg mercedesgk.jpg

and don't match your files in the code


static texture_info_t textures_info[] =
{
{ "/localhome/user/Temp/sample/marble.jpg", GL_RGB, 64, 0 },
{ "/localhome/user/Temp/sample/chess.jpg", GL_LUMINANCE, 64, 0},
// { "/localhome/user/Temp/sample/chrome.jpg", GL_RGB, 64, 0},
// { "/localhome/user/Temp/sample/mercedes.jpg", GL_RGB, 64, 0},
{ "/localhome/user/Temp/sample/satin.jpg", GL_RGB, 64, 0},
{ "/localhome/user/Temp/sample/outline.jpg", GL_LUMINANCE, 64, 0},
{ "/localhome/user/Temp/sample/marble.jpg", GL_RGB, 64, 0},
{ "/localhome/user/Temp/sample/marble.jpg", GL_RGB, 64, 0},
// { "satin.jpg", GL_RGB, 64, 0},
// { "satin.jpg", GL_RGB, 64, 0},
// { "logo.jpg", GL_RGB, 64, 0},
// { "logo2.jpg", GL_RGB, 64, 0},
{ "/localhome/user/Temp/sample/blank.jpg", GL_RGB, 128, 0},
{ NULL, 0, 0, 0}
};


Where's the download for "satin.jpg"? "outline.jpg"?

Do the pixel dimensions make sense for the downloaded files?


identify krisna12/*
krisna12/blankcr.jpg JPEG 128x128 128x128+0+0 8-bit DirectClass 907b
krisna12/chessx.jpg[1] JPEG 64x64 64x64+0+0 8-bit PseudoClass 256c 237b
krisna12/chromecd.jpg[2] JPEG 64x64 64x64+0+0 8-bit DirectClass 1.2kb
krisna12/golds.jpg[3] JPEG 64x64 64x64+0+0 8-bit DirectClass 705b
krisna12/marblel.jpg[4] JPEG 64x64 64x64+0+0 8-bit DirectClass 2.28kb
krisna12/mercedesgk.jpg[5] JPEG 64x64 64x64+0+0 8-bit DirectClass 416b

Krishna12
01-15-2010, 01:29 AM
Hi,

Thank you Very much.

The pixel dimension are same as they in the above post.

The images are placed with the same name which i specified. but i dont know why the names of the images are changing.

and satin.jpg and outline.jpg are similarly there in my folder,but i dint loaded that's it.


Could you link the code which you are executing in your system ?

please help me from this why it is not displaying images ?

Thanking you.

marshats
01-20-2010, 09:28 PM
The code runs fine on my machine provided you set the following _exactly_ as is:



static texture_info_t textures_info[] =
{
{ "marble.jpg", GL_RGB, 64, 0 },
{ "chess.jpg", GL_LUMINANCE, 64, 0},
{ "chrome.jpg", GL_RGB, 64, 0},
{ "mercedes.jpg", GL_RGB, 64, 0},
{ "satin.jpg", GL_RGB, 64, 0},
{ "outline.jpg", GL_LUMINANCE, 64, 0},
{ "marble.jpg", GL_RGB, 64, 0},
{ "marble.jpg", GL_RGB, 64, 0},
{ "satin.jpg", GL_RGB, 64, 0},
{ "satin.jpg", GL_RGB, 64, 0},
{ "logo.jpg", GL_RGB, 64, 0},
{ "logo2.jpg", GL_RGB, 64, 0},
{ "blank.jpg", GL_RGB, 128, 0},
{ NULL, 0, 0, 0}
};


The reason that you cannot comment out lines/image references in this code segment at random (just because you don't use them) is because the code is referencing textures_info[10], textures_info[11], and textures_info[12] explicitly elsewhere. If you want to comment out textures then you have to fix the code to not reference textures_info[10], [11], [12] accordingly.