Question

Texture Mapping a gluSphere

Asked by: studentuk

I know this is a pretty simple thing but i have been struggling with it, i know how to texture map a square etc, but im not sure how to create or imput the coordinates to texture map a shere. this is what im trying to do:

any help would be appreciated, thank you.

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texturesphere[0]);	
//	texture coordinate needs to be here
	gluSphere(quadratic,_Radius,1000,1000);
                                  
1:
2:
3:
4:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2008-04-08 at 02:15:50ID23303918
Tags

C++, OpenGL

Topics

Graphics & Game Programming

,

3D Game Programming

,

C++ Programming Language

Participating Experts
1
Points
500
Comments
29

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. OpenGL Texture Mapping
    Hey folks, I need a piece of Delphi4-code that makes use of plain OpenGL-syntax and does the following: A rectangle with a texture on it (loaded from a BMP) turning e.g. around the z-axis with a background image (also loaded from a BMP) behind the scene. The main problem is ...
  2. OpenGL texture mapping
    How can I map a texture automatically in OpenGl ??? I tried to use OpenGl's automatic texture coord generation, but it don't seems to work. mad666@infovia.com.ar
  3. Texture mapping
    I am using Visual Basic to write with OpenGL. When I try and texture map my objects, I find that the maximum size of texture map i can use is 256x256. Has anyone else found this to be the case, and is there a solution? (I thought of sticking many smaller textures together, bu...
  4. texture mapping
    hi all, how to texture map a cylinder sphere or any arbitrary object in opengl.i want the entire commands not any LINKS. prabhu
  5. texture map
    For some reason the texture is not being applied to the polygon. it draws the polygon with the last color set. what is wrong with the code? as it is obivous from the looking at the code, it is using MFC/C++. no glut* solutions please. and ignore potential memory leaks, etc. i...
  6. 3D textures
    I am using OpenGL 3D textures for my project, and I need to be able to slice the texture with a plane, displaying intersection image. The texture, as I understand, is loaded into a unit cube (coordinates normalized to [0,1] range). So when I cut it with an image plane in some...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ikeworkPosted on 2008-04-08 at 13:28:17ID: 21309260

when you create your GLUquadric-object, you have to tell glu to create texture-coords for the object with:

void gluQuadricTexture( GLUquadric* quad, GLboolean texture )

http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/quadrictexture.html


GLUquadric *quadratic = gluNewQuadric();
gluQuadricTexture( quadratic, true );  // << add this line after creating the quadric

..

// rendering is just like this then
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texturesphere[0]);
gluSphere(quadratic,_Radius,1000,1000);


ike

 

by: studentukPosted on 2008-04-09 at 06:25:40ID: 21314583

When trying that i get this error:

.\Sphere.cpp(42) : error C2662: 'Sphere::gluQuadricTexture' : cannot convert 'this' pointer from 'const Sphere' to 'Sphere &'
        Conversion loses qualifiers

 

by: ikeworkPosted on 2008-04-09 at 08:22:04ID: 21315878

please show the code

 

by: studentukPosted on 2008-04-09 at 08:35:53ID: 21316022

//In my Sphere.h
	void gluQuadricTexture(GLUquadric* quad, GLboolean texture);
 
//In my Sphere.cpp
	GLUquadric *quadratic = gluNewQuadric();
	gluQuadricNormals(quadratic, GLU_SMOOTH);
	gluQuadricTexture(quadratic, GL_TRUE);
	//Render
	glBindTexture(GL_TEXTURE_2D, texturesphere[0]);	
	gluSphere(quadratic,_Radius,1000,1000);
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

 

by: ikeworkPosted on 2008-04-09 at 08:38:00ID: 21316048

remove the declaration of "gluQuadricTexture" from your header, it is declared in glut.h

 

by: studentukPosted on 2008-04-09 at 09:06:43ID: 21316331

uhmm it compiles but its not working im going to check everything else as i think the fault might be somewhere else. thanks for the help so far

 

by: ikeworkPosted on 2008-04-09 at 11:01:05ID: 21317391

what excactly do you mean with "its not working". what was rendered?

 

by: studentukPosted on 2008-04-09 at 11:02:20ID: 21317408

Just the sphere itself no texture.

 

by: ikeworkPosted on 2008-04-09 at 11:26:06ID: 21317646

>> Just the sphere itself no texture.

wireframe or solid?


did you enable textures with:

glEnable( GL_TEXTURE_2D );

 

by: studentukPosted on 2008-04-10 at 00:26:01ID: 21322428

i did enable yes and its solid

 

by: studentukPosted on 2008-04-11 at 00:30:30ID: 21331942

Ok so ive been trying different things and i still cant get it to work, changed a few things round and im now using the nehe texture code, ill post below to show what ive done, i get the same result as before

//Nehe GL stuff
AUX_RGBImageRec *LoadBMP(char *Filename)				// Loads A Bitmap Image
{
	FILE *File=NULL;									// File Handle
 
	if (!Filename)										// Make Sure A Filename Was Given
	{
		return NULL;									// If Not Return NULL
	}
 
	File=fopen(Filename,"r");							// Check To See If The File Exists
 
	if (File)											// Does The File Exist?
	{
		fclose(File);									// Close The Handle
		return auxDIBImageLoad(Filename);				// Load The Bitmap And Return A Pointer
	}
 
	return NULL;										// If Load Failed Return NULL
}
 
int LoadGLTextures()									// Load Bitmaps And Convert To Textures
{
	int Status=FALSE;									// Status Indicator
	AUX_RGBImageRec *TextureImage[1];					// Create Storage Space For The Texture
	memset(TextureImage,0,sizeof(void *)*1);           	// Set The Pointer To NULL
	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if (TextureImage[0]=LoadBMP("Data/Crate.bmp"))
	{
		Status=TRUE;									// Set The Status To TRUE
		glGenTextures(3, &texture[0]);					// Create Three Textures
		// Create Nearest Filtered Texture
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		// Create Linear Filtered Texture
		glBindTexture(GL_TEXTURE_2D, texture[1]);
		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, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
		// Create MipMapped Texture
		glBindTexture(GL_TEXTURE_2D, texture[2]);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
	}
 
	if (TextureImage[0])								// If Texture Exists
	{
		if (TextureImage[0]->data)						// If Texture Image Exists
		{
			free(TextureImage[0]->data);				// Free The Texture Image Memory
		}
		free(TextureImage[0]);							// Free The Image Structure
	}
	return Status;										// Return The Status
}
 
 
 
 
//Draw Method for sphere
 
void drawsphere(void)
{
	glPushMatrix();
	glTranslatef(0.0f,0.0f,0.0f);
	glRotatef(JupitersRotation,3.0,0,0);
	//Enable Textures
	glEnable(GL_TEXTURE_2D);
	
	GLUquadric *quadratic = gluNewQuadric();
	gluQuadricNormals(quadratic, GLU_SMOOTH);
	gluQuadricTexture(quadratic, GL_TRUE);
	//Render
	glBindTexture(GL_TEXTURE_2D, texture[0]);	
	gluSphere(quadratic,radius,1000,1000);
	glDisable(GL_TEXTURE_2D);
	glPopMatrix();
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:

Select allOpen in new window

 

by: ikeworkPosted on 2008-04-11 at 09:59:55ID: 21336024

check the sizes of your texture, only powers of 2 are allowed and width and height must be the same, like {32,32},  {64,64}, {128,128} etc
if the size is ok, can you bind the texture to a simple object, like a triangle?

 

by: studentukPosted on 2008-04-11 at 12:59:44ID: 21337675

the size is right yes, ive also tried loading it onto a cube with no luck

 

by: ikeworkPosted on 2008-04-12 at 01:35:27ID: 21340272

here is code how to render it on a quad. if it doesnt work most likely the problem is that the texture was not loaded properly

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture[0]); 
    static const float size_half = 5.0f;
    glBegin( GL_QUADS );
        glTexCoord2f( 0.0f, 0.0f );
        glVertex3f( -size_half, -size_half, 0.0f );
        glTexCoord2f( 0.0f, 1.0f );
        glVertex3f( -size_half,  size_half, 0.0f );
        glTexCoord2f( 1.0f, 1.0f );
        glVertex3f(  size_half,  size_half, 0.0f );
        glTexCoord2f( 1.0f, 0.0f );
        glVertex3f(  size_half, -size_half, 0.0f );
    glEnd();
    glDisable(GL_TEXTURE_2D);
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:

Select allOpen in new window

 

by: ikeworkPosted on 2008-04-12 at 01:36:02ID: 21340274

if it does not work, please upload the texture, i'm gonna have a look at it ..

 

by: studentukPosted on 2008-04-12 at 02:04:21ID: 21340342

Still nothing, the texture im using is just one from nehe, i was using my own but i swapped it as i thought it could be that, it seems the texture still isnt loading.  I am recieving this error

\documents\visual studio 2005\projects\jupiterrising_beta1\jupiterrising_beta1\main_app.cpp(77) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\program files\microsoft visual studio 8\vc\include\stdio.h(234) : see declaration of 'fopen'

 

by: ikeworkPosted on 2008-04-12 at 02:12:23ID: 21340357

you can ignore this warning, it just says that in the future this function will not be there anymore. but that is not the cause of the problem.
can you set a breakpoint, where the fopen-call is and see if it succeeds?

feel free tp post the code here and i'm gonna try it. please put the texture then as well.

 

by: ikeworkPosted on 2008-04-12 at 02:17:20ID: 21340360

check the returnvalue of LoadGLTextures(), it is supposed to be "TRUE", if loading failed it is "FALSE".

 

by: ikeworkPosted on 2008-04-12 at 02:22:03ID: 21340362

i guess the problem is the relative path of your texture-file  

  LoadBMP("Data/Crate.bmp");

try to use an absolute path:

  LoadBMP("c:/wherever/Data/Crate.bmp");

 

by: studentukPosted on 2008-04-12 at 02:31:05ID: 21340382

ive attatched the file im using just to try get it working

Been playing with breakpoints, heres some issues i can find
 
		TextureImage[0]	0x00000000 {sizeX=??? sizeY=??? data=??? }	_AUX_RGBImageRec *
		sizeX	CXX0030: Error: expression cannot be evaluated	
		sizeY	CXX0030: Error: expression cannot be evaluated	
		data	CXX0030: Error: expression cannot be evaluated	
 
		Status	0	int
and:
-		TextureImage	0x0012fe48	_AUX_RGBImageRec * [1]
+		[0]	0x00000000 {sizeX=??? sizeY=??? data=??? }	_AUX_RGBImageRec *

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

 

by: ikeworkPosted on 2008-04-12 at 02:36:05ID: 21340390

>> TextureImage[0] 0x00000000

well, that means the LoadBMP-function failed. did you try to set the texture-file-path absolutely, like i showed you above:

  LoadBMP("c:/wherever/Data/Crate.bmp");

 

by: studentukPosted on 2008-04-12 at 02:36:48ID: 21340392

yeah i did

 

by: ikeworkPosted on 2008-04-12 at 02:40:06ID: 21340395

well as i said, put a breakpoint in this line

   File=fopen(Filename,"r");  

in LoadBMP. if it fails, then the next if-statement will fail as well, then you know something is wrong with your filename/filepath.

 

by: studentukPosted on 2008-04-12 at 02:42:43ID: 21340401

uhmm this is the result

-            File      0x00000000 {_ptr=??? _cnt=??? _base=??? ...}      _iobuf *
            _ptr      CXX0030: Error: expression cannot be evaluated      
            _cnt      CXX0030: Error: expression cannot be evaluated      
            _base      CXX0030: Error: expression cannot be evaluated      
            _flag      CXX0030: Error: expression cannot be evaluated      
            _file      CXX0030: Error: expression cannot be evaluated      
            _charbuf      CXX0030: Error: expression cannot be evaluated      
            _bufsiz      CXX0030: Error: expression cannot be evaluated      
            _tmpfname      CXX0030: Error: expression cannot be evaluated

-            Filename      0x00428348 "C:UsersGrahamDocumentsVisual Studio 2005Projectsdemo1DataCrate.bmp"      char *
                  67 'C'      char

 

by: ikeworkPosted on 2008-04-12 at 02:45:05ID: 21340408

look at the filename:

   "C:UsersGrahamDocumentsVisual Studio 2005Projectsdemo1DataCrate.bmp"

thats the cause of your problem. if you used backslashes, "\" then you have to double it "\\". anyway please post the original string you used for the filename

 

by: studentukPosted on 2008-04-12 at 03:05:09ID: 21340436

Ok, by adding double slashes it worked on the square, and now on the sphere, thank you, out of curiosity why do you need to use double slashes when sending in a file directory?

 

by: ikeworkPosted on 2008-04-12 at 03:12:08ID: 21340453

the normal slash, if used in string constants is used for control-sequences, like "\r" for return "\t" for a tab. if you use "\\" the compiler knows you dont want to begin such a sequence

 

by: ikeworkPosted on 2008-04-12 at 03:13:03ID: 21340455

>> Ok, by adding double slashes it worked on the square, and now on the sphere, thank you

why dont you close the question then?

 

by: studentukPosted on 2008-04-12 at 03:15:02ID: 31446863

'why dont you close the question then?' was in the middle of doing so im on a slow line today, thanks for the help

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...