3D sphere texturing and manipulation. -Using LWJGL and Slick Util

Hello JGO!
I thought I wouldn’t be asking another newb question for a while, but I got SFX greedy.

For my intro of my game, I want the earth and sun spinning around, and, I could draw an undynamic animation or array of .png files, or I could draw a sphere to do it for me, and considering it’s going to be the only 3D in my game (planned so far), it shouldn’t be too bad to implement.

A few problems with the code below:

  • It uses the slick Texture to bind to the glu.sphere, but it only shows the average colour- there is only 1 colour.
  • I cannot understand how to map the texture if I got it working
  • Only the leftmost and rightmost pixels are processed from the .png to the sphere
  • Transparency only whitens the sphere.
private static Texture image;
private void renderSphere(float x, float y, float z) 
	{
		image.bind();
		glPushMatrix();
		glTranslatef(x, y, z);
		Sphere s = new Sphere();
		s.draw(0.4f, 16, 16);
		glPopMatrix();
	}

So any ideas? I cannot understand how it does work.

What do you mean “average color” ? If it renders as a solid color, its probably a sign that [icode]GL_TEXTURE_2D[/icode] is not enabled. Further, SlickUtil is kind of buggy depending on the version you have.

I would just bind the texture directly:

//enable transparency
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

//enable and bind the texture
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());

..render sphere...

Even with all of that, it might not work. I’m not familiar with LWJGL’s GLU emulation and I’m not sure how it handles texture coordinates. GLU is really old and for the most part only used for simple debugging.

Rendering a sphere in OpenGL isn’t too difficult, and actually is a good way to introduce yourself to modern OpenGL. It basically comes down to spherical coordinates:


If you can’t get it working and can’t be bothered to learn the OpenGL way, I would suggest just using LibGDX, jME, jPCT, or another library to help you with the 3D aspects.

Yes, spherical coords. You could approximate texture coords from 0 to 2PI in both the azimuth and horizon.

www.rel.phatcode.net/junk.php?id=61

Oh… god. I’ve never seen such a trippy thing in my life… Now I just need to figure out what this .bas file says… and how to use it’s equations hidden within the syntax.

Thanks for the links! About glu.Sphere, I am new to it, so I figured out that a texture to wrap it around should have many colours, as to see which pixel to attach where, but it seems It just blurs it into the texture’s average colour and then implements it. Also, GL_TEXTURE_2D was enabled, as I was using other textures at the time as well.

It’s a supershape morpher I made from the equations developed by Paul Bourke.

www.paulbourke.net/geometry/

Basically, I already had a working tesselator for quadric shapes so I only have to enter the equations, do some interpolation to its parameters.

Bas files are BASIC code(freebasic.net). One of the languages I code for fun. :slight_smile:

I’d be happy to walk you through the code if you want. :slight_smile:

Erf… I would like a walk-through for this please.