PDA

View Full Version : Texture map on a gluSphere



starman
02-24-2003, 07:51 AM
I'm trying to texture map a gluSphere with a mercator map of the earth. I've set up the right quadric calls (gluQuadricTexture, gluQuadricNormals, etc.) and the texture appears, but there are "holes" in it. When I rotate the sphere, lots of triangular and rectangular shaped holes flicker about, making it look terrible.

I'm guessing it has to do with how I'm setting up the texture parameters. I've tried different textures at different resolutions and they all exhibit the problem.

Can anyone that's successfully done this show me the code they used to set the texture parameters? Anything else I might be overlooking?

nexusone
02-24-2003, 08:09 AM
Look at the glball demo on my website, uses glusphere with mapped texture.
http://www.angelfire.com/linux/nexusone/index.html

starman
02-24-2003, 09:07 AM
Thanks. Just eyeballing your code it looks like mine (can't get to it from work). I'll play around with mine some more tonight and post a code snippet and a screen shot if I'm still having trouble.

starman
02-24-2003, 04:25 PM
Looks like it has nothing to do with texture mapping. I disabled textures and colored the sphere red. Here is what it looks like:
http://home.columbus.rr.com/bk99/dm/Clip2.jpg

Any ideas? Depth testing is on, face culling is on, lighting and textures are disabled. Seems pretty simple.

nexusone
02-24-2003, 04:57 PM
Let me see your code maybe try to compile it...
BTW did you try and compile my demo and see if you get the same results on your computer?



Originally posted by starman:
Looks like it has nothing to do with texture mapping. I disabled textures and colored the sphere red. Here is what it looks like:
http://home.columbus.rr.com/bk99/dm/Clip2.jpg

Any ideas? Depth testing is on, face culling is on, lighting and textures are disabled. Seems pretty simple.

starman
02-24-2003, 05:50 PM
My app is a CPP Builder app. I pared it down to a small subset, but you would have to cut and paste the OpenGL stuff to a GLUT app. I don't have GLUT and don't know much about it:

#include <vcl.h>
#include <string>
#include <mmsystem.h>
#include <sstream>
#include <iomanip>
#include "GLFormUnit.h"
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#pragma hdrstop
#pragma resource "*.dfm"

using std::string;

TGLForm * GLForm;

static GLUquadricObj * quadric_;

static void checkGLErrors()
{
GLenum errCode;
const GLubyte * glErr;

if ((errCode = glGetError()) != GL_NO_ERROR) {
glErr = gluErrorString(errCode);
Application->MessageBox(glErr, "OpenGL Error", MB_OK);
}
}

__fastcall TGLForm::TGLForm(TComponent * Owner) : TForm(Owner) {}

void __fastcall TGLForm::IdleLoop(TObject *, bool & done)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

// draw red ball
static float rot = 1.0f;
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
glRotatef(rot, 0.0f, 1.0f, 0.0f);
gluSphere(quadric_, 2.0f, 30, 30);
rot += 0.1;

done = false;
SwapBuffers(deviceContext_);
}

void __fastcall TGLForm::FormCreate(TObject * Sender)
{
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);

quadric_ = gluNewQuadric();
gluQuadricDrawStyle(quadric_, GLU_FILL);

Application->OnIdle = IdleLoop;
deviceContext_ = GetDC(GLPanel->Handle);
SetPixelFormatDescriptor();
renderContext_ = wglCreateContext(deviceContext_);
wglMakeCurrent(deviceContext_, renderContext_);
}

void __fastcall TGLForm::FormDestroy(TObject * Sender)
{
checkGLErrors();
gluDeleteQuadric(quadric_);

ReleaseDC(deviceContext_, 0);
wglMakeCurrent(deviceContext_, NULL);
wglDeleteContext(renderContext_);
}

void __fastcall TGLForm::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24,
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
pixelFormat_ = ChoosePixelFormat(deviceContext_, &pfd);
SetPixelFormat(deviceContext_, pixelFormat_, &pfd);
}

void __fastcall TGLForm::FormResize(TObject * Sender)
{
float width = GLPanel->Width;
float height = GLPanel->ClientHeight;

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (float) width / (float) height, 0.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

nexusone
02-24-2003, 06:33 PM
A few diffrences from mine:

Yours: static GLUquadricObj * quadric_;
Mine: GLUquadricObj * quadric_;

I wonder is the data is being croupted some how?

Try not using it as a static varaible.

SThomas
02-24-2003, 06:56 PM
in your TGLForm::FormCreate() method, it looks like you're making opengl calls before you create your rendering context. try making those calls after you create the rendering context.

starman
02-24-2003, 07:11 PM
Tried making the quadric_ not static - that didn't help.

Moving the rendering calls after creating the rendering context exacerbated the problem! Interesting.

SThomas
02-24-2003, 07:35 PM
well, if you make gl calls without a valid rendering context the calls are just ignored. so you do want the gl calls after you create the rendering context, and not before. i guess there are other problems as well. after moving the calls, what kinds of problems are you having? same deal only worse?

the only thing i see is that you enable face culling without specifying which face to cull (front/back) and which face is the front face (clockwise/counterclockwise). try adding this (and make sure to place it after you create the rendering context of course):

glFrontFace(GL_CCW); //or GL_CW for clockwise front face
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE); //which you already have

i doubt this is the problem though.

SThomas
02-24-2003, 07:48 PM
ah, don't know how i missed this...



gluPerspective(60.0, (float) width / (float) height, 0.0, 100.0);

a near plane of 0.0 is no good. you need to push the near plane out. the ratio far plane / near plane should basically be as low as possible, but yours is infinity. make the near plane 0.1 (or higher) and that should fix everything.

Namwob
02-24-2003, 08:08 PM
I've already done what you're trying to do, but I'm not using gluSphere -- I did it the hard way drawing my own sphere out of polygons and splitting up the texture map into small texture maps on each polygon. If you're still having problems and would like the function I used to draw it, e-mail me at bowmanerik at ixpres.com (@sign removed to prevent spambots from getting me) -- I'll send you the code and bitmaps I used -- it's in C++, so if you're using VB, this won't work.

starman
02-25-2003, 12:56 AM
Give that man a cigar!! My near plane of 0.0 was indeed the problem. Thank you and thanks to all who contributed in such a timely fashion!

nexusone
02-25-2003, 04:51 AM
Good show 'SThomas', I also overlooked the gluperspective.... must not be less then 1.0 for the near setting.

Bob
02-25-2003, 05:15 AM
Originally posted by nexusone:
...must not be less then 1.0 for the near setting.

The near plane can be any positive value, including values less than 1.

nexusone
02-25-2003, 05:29 AM
I could be wrong, but I remember reading in a book something about the closer to zero you could have problems.

And I think someone in the past on this forum was having trouble because of it, his number's where greater then zero... something like 0.01 but it cause a problem.
going to 1.0 corrected it.

I just always keep perspective at 1.0 or greater.



Originally posted by Bob:

Originally posted by nexusone:
...must not be less then 1.0 for the near setting.

The near plane can be any positive value, including values less than 1.

Bob
02-25-2003, 02:39 PM
The problem is not dependent on the near value, but the near value relative the far value. Having the near plane way below 1 is OK as long as the far plane is not too far out. And a near value of 1 can be way too small if the far clip plane is too far away.