Adrian Hooper
03-12-2009, 08:41 AM
I've created a hemisphere with the following code :
list = gl.glGenLists(1);
int radius = 1060;
final double deg_to_rad = Math.PI / 180;
final double rad_to_deg = 180 / Math.PI;
double x, y, z;
//gl.glPolygonMode (GL.GL_FRONT_AND_BACK, GL.GL_LINE);
gl.glNewList(list, GL.GL_COMPILE);
for (double phi = 0.0; phi <= 80.0; phi += 10.0) {
gl.glBegin(GL.GL_QUAD_STRIP);
for (double theta = -180.0; theta <= 180.0; theta += 10.0) {
x = radius * Math.sin(Math.PI/180 * theta) * Math.cos(Math.PI/180 * phi);
y = radius * Math.cos(Math.PI/180 * theta) * Math.cos(Math.PI/180 * phi);
z = radius * Math.sin(Math.PI/180 * phi);
gl.glVertex3d (x,y,z);
x = radius * Math.sin(Math.PI/180 * theta) * Math.cos(Math.PI/180 * (phi + 10.0));
y = radius * Math.cos(Math.PI/180 * theta) * Math.cos(Math.PI/180 * (phi + 10.0));
z = radius * Math.sin(Math.PI/180 * (phi + 10.0));
gl.glVertex3d (x,y,z);
}
gl.glEnd();
}
gl.glEndList();
This seems to work and creates a hemisphere (slightly strangely though) and now I want to texture it to display my sky image.
I've used a number of things to try and it is texturing it, but very strangely :(
gl.glBindTexture(GL.GL_TEXTURE_2D, textures[0]);
gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE,GL.GL_SPHERE_MAP);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
gl.glCallList(list);
I'm using this to bind the texture but it seems to be repeating the texture thousands of times in tiny segments rather than wrapping it around. How can I do it?
Thanks
And sorry, it's using JOGL rather than pure openGL but I can convert between the two
list = gl.glGenLists(1);
int radius = 1060;
final double deg_to_rad = Math.PI / 180;
final double rad_to_deg = 180 / Math.PI;
double x, y, z;
//gl.glPolygonMode (GL.GL_FRONT_AND_BACK, GL.GL_LINE);
gl.glNewList(list, GL.GL_COMPILE);
for (double phi = 0.0; phi <= 80.0; phi += 10.0) {
gl.glBegin(GL.GL_QUAD_STRIP);
for (double theta = -180.0; theta <= 180.0; theta += 10.0) {
x = radius * Math.sin(Math.PI/180 * theta) * Math.cos(Math.PI/180 * phi);
y = radius * Math.cos(Math.PI/180 * theta) * Math.cos(Math.PI/180 * phi);
z = radius * Math.sin(Math.PI/180 * phi);
gl.glVertex3d (x,y,z);
x = radius * Math.sin(Math.PI/180 * theta) * Math.cos(Math.PI/180 * (phi + 10.0));
y = radius * Math.cos(Math.PI/180 * theta) * Math.cos(Math.PI/180 * (phi + 10.0));
z = radius * Math.sin(Math.PI/180 * (phi + 10.0));
gl.glVertex3d (x,y,z);
}
gl.glEnd();
}
gl.glEndList();
This seems to work and creates a hemisphere (slightly strangely though) and now I want to texture it to display my sky image.
I've used a number of things to try and it is texturing it, but very strangely :(
gl.glBindTexture(GL.GL_TEXTURE_2D, textures[0]);
gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE,GL.GL_SPHERE_MAP);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
gl.glCallList(list);
I'm using this to bind the texture but it seems to be repeating the texture thousands of times in tiny segments rather than wrapping it around. How can I do it?
Thanks
And sorry, it's using JOGL rather than pure openGL but I can convert between the two