gluQuadricTexture coords

Hi all,

I am trying to map a video onto a cylinder to simulate a 360 degree cinema screen. I have this partly working thanks to another thread but the problem is that my video doesn’t cover the entire surface. I have not been able to find a way to get gluQuadricTexture() to set the texture coords differently. Any advice appreciated, code below:

  
#include "testApp.h"  
  
ofTexture myTexture;  
ofTextureData myTextureData;  
GLUquadricObj *quadratic = NULL;  
double base = 250;  
double top = 250;  
double h = 150;  
double slices = 40;  
double stacks = 1;  
  
//--------------------------------------------------------------  
void testApp::setup(){  
	  
	ofDisableArbTex();  
  
	vid.loadMovie("vid.mov");  
	vid.setUseTexture(false);  
  
	myTexture.allocate(vid.width, vid.height, GL_RGB, false);	  
	myTexture.loadData(vid.getPixels(),vid.width, vid.height, GL_RGB);  
	//myTextureData = myTexture.getTextureData();  
	  
	quadratic = gluNewQuadric();  
	gluQuadricTexture(quadratic, GL_TRUE);      // Create Texture Coords  
	//gluQuadricTexture(quadratic, GLU_OUTSIDE);   
	//gluQuadricDrawStyle(quadratic, GLU_FILL);  
	//gluQuadricNormals(quadratic, GLU_SMOOTH);   
	  
	glEnable(GL_DEPTH_TEST);  
  
	vid.play();  
	  
	ofBackground(10,10,10);  
  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
	vid.idleMovie();  
	myTexture.loadData(vid.getPixels(),vid.width, vid.height, GL_RGB);  
	  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	myTexture.draw(0,0);  
  
	glPushMatrix();  
		ofSetColor(255,255,255);  
		myTexture.bind();  
		glTranslatef(ofGetWidth()*0.5, ofGetHeight()*0.5, 0.0);  
		glRotatef(230,1,0,0);  
		gluCylinder(quadratic, base, top, h, slices, stacks);		  
		myTexture.unbind();  
	glPopMatrix();  
	  
}  

Still stuck on this one. In the glyCylinder man page it says:

  
If texturing is turned on (with gluQuadricTexture), then texture coordinates  
			are generated so that t ranges linearly from 0.0 at   
					z  
					=  
					0  
				 to 1.0 at   
					z  
					=  
					height  
				, and s ranges from 0.0 at the   
					+  
					y  
				 axis, to 0.25 at the   
					+  
					x  
				 axis, to 0.5 at the   
					-  
					y  
				 axis, to 0.75 at the   
					-  
					x  
				 axis, and back to 1.0 at the   
					+  
					y  
				 axis.  

So the prob is that I need to change these ranges before automatically generating the texture coordinates. Is this even possible? or do I need to manually draw the cylinder and specify the texture coord at each vertice?

alrighty, so I am now building the cylinder by hand using a quad strip. But I am having trouble getting the texture coordinates to align properly. Can anyone spot what I’m doing wrong here? It looks like a single pixel row of the texture is being stretched along the z-axis.

  
#include "testApp.h"  
  
ofTexture myTexture;  
ofTextureData myTextureData;  
  
//--------------------------------------------------------------  
void testApp::setup(){  
	  
	ofDisableArbTex();  
  
	vid.loadMovie("vid.mov");  
	vid.setUseTexture(false);  
	  
	myTexture.allocate(vid.width, vid.height, GL_RGB, false);	  
	myTexture.loadData(vid.getPixels(),vid.width, vid.height, GL_RGB);  
	  
	glEnable(GL_DEPTH_TEST);  
	  
	vid.play();  
	  
	ofBackground(10,10,10);  
  
}  
  
//--------------------------------------------------------------  
void testApp::update(){  
	vid.idleMovie();  
	myTexture.loadData(vid.getPixels(),vid.width, vid.height, GL_RGB);  
}  
  
//--------------------------------------------------------------  
void testApp::draw(){  
	myTexture.draw(0,0);  
	myTexture.bind();  
	ofSetColor(255,255,255);  
	  
	glPushMatrix();  
	  
		glTranslatef(ofGetWidth()*0.5, ofGetHeight()*0.5, 0.0);  
		glRotatef(230,1,0,0);	  
		  
		float x = 0;  
		float y = 0;  
		float inc = 360/12;  
		float h = 100;  
		float scale = 200;  
  
		glBegin(GL_QUAD_STRIP);  
		for(int i = 0; i <= 360; i+=inc){  
			  
			x =  scale  * sin(i*DEG_TO_RAD);  
			y =  scale  * cos(i*DEG_TO_RAD);  
  
			glTexCoord3f(x/scale,y/scale,0);  
			glVertex3f(x,y,0);  
			  
			glTexCoord3f(x/scale,y/scale,1);  
			glVertex3f(x,y,h);  
  
		}  
		glEnd();  
  
	glPopMatrix();  
  
	myTexture.unbind();  
  
}  

i guess i need to find a way to use glTexCoord2f instead or something but can’t get my head around how.

bit of a feedback loop unto myself here! hope someone else finds this useful. i have it working now with:

  
		float x = 0;  
		float y = 0;  
		float slice = 24;  
		float inc = 360/slice;  
		float h = 100;  
		float scale = 200;  
  
		glBegin(GL_QUAD_STRIP);  
		for(int i = 0; i <= 360; i+=inc){  
			  
			x =  scale  * sin(i*DEG_TO_RAD);  
			y =  scale  * cos(i*DEG_TO_RAD);  
  
			float x_pos = i/inc *(.62/slice);  
			  
			glTexCoord2f(x_pos,0);  
			glVertex3f(x,y,0);  
			  
			glTexCoord2f(x_pos,.93);  
			glVertex3f(x,y,h);  
  
		}  
		glEnd();  

However, the .62 and .93 used with glTexCoord2f() seem completely arbitrary to me, but these are the values that get the texture to align with the edges of the quad strip.

Not sure but maybe you can use ofDisableArbTex() before loading your texture.

Check this post about gluSphere. Should be similar to gluCylinder:

http://forum.openframeworks.cc/t/texturing-a-glusphere/1942/0

thanks. i had to call that to get glucylinder to work, but not when drawing it manually as in my last post. i had to do it manually though as I couldn’t get the text coords to line up with glucylinder using the same method as the glusphere thread.