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