How to draw 3D rotating Cylinder

I was able to replicate your error if the image file was not loaded ie some error like it being an invalid image file. The error your reported was not due to my original suspicion of the image file sizes.

Your images are reporting incorrectly that they are RGB format but they are actually RGBA … To fix this change the line in ILuint LoadImageDevIL (const char *szFileName, struct TextureHandle *T)


ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
to
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

Hi,

Thank you so much for the reply.

Now i am getting the cylinder(Like an arc) with image rotating on that.

In that arc like cylinder only logo.jpg is displaying and logo2.jpg is missing on the surface of the cylinder.

You are getting complete Cylinder with both images ?

I am thankful for your reply…

Yes, all the images show up fine with the GL_RGBA change.

Can you post your code?

Hi,

Thanks for the replying.

The code which is executing in my system is posted below :

 

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

#include <IL/il.h>

GLfloat gTexOffset = 0.0;
GLUquadricObj *IDquadric;

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;

ILuint LoadImageDevIL (const char *szFileName, struct TextureHandle *T)
{
  ilEnable(IL_ORIGIN_SET);

  ilOriginFunc(IL_ORIGIN_LOWER_LEFT);

  ILuint ImageNameID;
  ilGenImages(1, &ImageNameID);
  ilBindImage(ImageNameID);
  if (!ilLoadImage(szFileName)) return 0;


ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);


  T->id = ImageNameID;
  T->p = ilGetData();
  T->w = ilGetInteger(IL_IMAGE_WIDTH);
  T->h = ilGetInteger(IL_IMAGE_HEIGHT);

  T->DestFormat = ilGetInteger(IL_IMAGE_FORMAT);
  T->DestType = ilGetInteger(IL_IMAGE_TYPE);

  glGenTextures(1, &T->genID);
  glBindTexture(GL_TEXTURE_2D, T->genID);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexImage2D (GL_TEXTURE_2D, 0, T->DestFormat, T->w, T->h, 0, T->DestFormat, T->DestType, T->p);

  printf("%s %d %d %d
",szFileName,T->id,T->w,T->h);
  return 1;
}


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

  gTexOffset += dt*360./8.;

  glutPostRedisplay();
}


void draw_cylinder()
{
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glTranslatef(-5.,0,-100);
  glRotatef(45,1.,1.,0.);

  glMatrixMode(GL_TEXTURE);
  glLoadIdentity();
                                 
  glTranslatef(0.,gTexOffset/100.,0);

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

  glMatrixMode(GL_MODELVIEW);
  glPopMatrix();
}


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

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

  glutSwapBuffers();
}




void placeTexture(GLuint M, GLuint N, GLuint i, GLuint j, GLuint genID)
{
  
  GLfloat X1 = (GLfloat) i / (GLfloat) M;
  GLfloat X2 = X1 + (GLfloat) 1 / (GLfloat) M;
  GLfloat Y1 = (GLfloat) j / (GLfloat) N;
  GLfloat Y2 = Y1 + (GLfloat) 1 / (GLfloat) N;

  glBindTexture ( GL_TEXTURE_2D, genID);
  glBegin(GL_QUADS);
  glTexCoord2f(0,0); glVertex2f(X1,Y1);
  glTexCoord2f(1,0); glVertex2f(X2,Y1);
  glTexCoord2f(1,1); glVertex2f(X2,Y2);
  glTexCoord2f(0,1); glVertex2f(X1,Y2);
  glEnd();
}


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

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

  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();
  glOrtho(0,1, 0,1, -1,1 );

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

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

 
  GLuint M = 2;
  GLuint N = 3;
  placeTexture(M,N, 0,0, logo.genID);  
  placeTexture(M,N, 1,0, logo2.genID); 

  placeTexture(M,N, 1,1, logo2.genID); 
  placeTexture(M,N, 0,2, logo.genID);  
  placeTexture(M,N, 1,2, logo2.genID); 

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

  LoadImageDevIL ("/localhome/user/Temp/sample/logo.jpg", &logo);
  LoadImageDevIL ("/localhome/user/Temp/sample/logo2.jpg", &logo2);

  LoadImageDevIL ("/localhome/user/Temp/sample/logoM.jpg", &logoM); 
  glEnable (GL_TEXTURE_2D);
}


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


int main(int argc, char** argv)
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
  glutCreateWindow("Multipass texturing Demo");
  glewInit();

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

  init();
  glutReshapeWindow(logoM.w,logoM.h); 

  glutMainLoop();
  return 0;
}


i am thankful for your reply.

hi i’ve a question…how do i draw a cylinder using basic polygons a not glucylinder…i should be able to colour my polygons on the surface of the cylinder as well…kindly send me the code…thankyou…

I am at a loss to explain your problem. The code with your jpg’s works fine on my machine.

What is your video card? what is your OS? what version of the libraries are you using: DevIL? freeglut? GL drivers?

This post is getting a little long and it is using gluQuadric – it would probably be best if you start a new thread for your question. If you are trying to simply texture you could try looking at the Redbook especially Chapter 9 and the Sample Code – checker.c is a good start. To turn that into a cylinder you would just have to change the " glTexCoord2f(…); glVertex3f(…);" in display().

Hi,

Thank You for replying.

I am currently working on virtual machine(Ubuntu) on my window system.
The version of VM is : 2.5.3 build-185404

and i installed Devil, GL libraries as you told the command
below:
sudo apt-get install libdevil-dev" command installation.

and i had a graphics controller : Intel®82845G/GL/GE/PE/GV Graphics controller. and my machine as 2GB RAM

is it possible to paste the output which is displaying on your machine ?
and could you send the versions of your Libraries ?

I am thankful for your replying.

I have never been able to get full openGL support thru a VM. That is a likely reason for the problem. I am using the default versions of libraries with NON-VM Ubuntu 9.10 (reading from synaptic):


libIL ... 1.7.8-2
freeglut 2.4-0-6ubuntu1
libglew ... 1.5.1-4ubuntu1

This code with your pics generates this picture:

This code with your pics generates this picture:

Post the results of running glewinfo form the command line from within your VM/Ubuntu machine:


glewinfo > glewinfo.txt

This may help spot some reasons for the problem. For comparison, running this command on my machine yields the following glewinfo.txt

Hi,

Thanks for replying.

The first output code which you pasted above is giving the Runtime message as below :

<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
user@lxdevenv:~/Desktop$ ./forcode
freeglut (./forcode): Unable to create direct context rendering for window ‘Multipass texturing Demo’
This may hurt performance.
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 12 (X_ConfigureWindow)
Value in failed request: 0x0
Serial number of failed request: 38
Current serial number in output stream: 39
cleanupQuadric completed
user@lxdevenv:~/Desktop$

[/QUOTE]</div>

and the second output is displayed on my System by making little changes in your code.

the above cylinder in output-2 should be placed like below figure :

http://img10.imageshack.us/i/untitu.png/

What to do for it ?

i am thankful for the reply.

Can you please run “glewinfo” and post the result here to see what your capabilities are? I still suspect you are running into a virtual machine issue not a GL/GLUT/libIL problem.

Hi,

Sorry for Late reply and Thank you for replying.

The information of glew is pasted in the below link, Please check it.

http://www.2shared.com/file/10885944/1a7d81e7/infoglee.html

i am Thankful for your reply.

The beginning of your link to glewinfo file was missing … it started with


 glGetInvariantIntegervEXT:                                   OK
  glGetLocalConstantBooleanvEXT:                               OK
  glGetLocalConstantFloatvEXT:                                 OK

I was looking for something more like


---------------------------
    GLEW Extension Info
---------------------------

GLEW version 1.5.1
Reporting capabilities of display :0.0, visual 0x2b
Running on a GeForce 9600 GT/PCI/SSE2/3DNOW! from NVIDIA Corporation
OpenGL version 3.2.0 NVIDIA 195.17 is supported

GL_VERSION_1_1:                                                OK 
...

Hi,

I am pleased for replying.

I tried twice, using “glewinfo” command but it is displaying the same information which is there in previous post.

I am thankful for your reply.

Try on the commandline the following


glewinfo | less

and


glewinfo > glewinfo.txt
gedit glewinfo.txt

The post the resultant file glewinfo.txt.

Hi,

Thank you So much for replying.
I uploaded the glewinfo.txt file. please download from the below link.

http://www.2shared.com/file/10949945/2900306d/glewinfo.html

What will be the problem ?

I am thankful for your reply.

That is an older version of Mesa. I am at a loss as to explain what the problem is.

However, one last thing to try is related to the images themselves. In older versions of openGL there was a requirement that the images have sizes that are powers of 2 ie length or width is 2,4,8,16, … 2^N. So I have resized your images to be 64x64. And in the code I added an “assert” to check if loadImage fails or not to give a more graceful failure if the image format has anything to do with the problem.

So download these images and try the code with added assert to check for image loading failure:
logo.jpg
logo2.jpg
logoM.jpg

code

If this does not work I do not know what else to try. It runs fine on my machine – NVIDIA GL drivers (not Mesa GL software drivers) and UBUNTU 9.10 with all latest updates (not in a virtual machine either).

Hi,

I am pleased for your replying.

I downloaded the images and executed the code which is there in above post.

The output i am getting is posted in below Link please check it.

http://img693.imageshack.us/i/rrriv.png/

Is this output your are expecting ?

I am Thankful for your reply.

Yes, that is what you should see.

Now try changing those image files and see if the errors come back but DO NOT recompile the code, just copy new jpg files into the same folder. I suspect your images have to be even powers of 2.

Hi,

Sorry for Late reply.

Thank you very much for your replying.

I am trying to do multitexturing on the cylinder(which is made up of polygons)surface.
i am not able to place multiple images on it.
I am not getting what is went wrong ?

i am loading three images, but it is displaying the 1st image on the surface.

The code is Herercms.c

output is Here output

Please Help me…

I am Thankful for your reply.