-2

I am working on a project to texture a sphere with a jpeg image and with some keyboard navigation keys for the user that rotates the sphere right or left. The problem is i tried using SOIL to load the image and it was successfully loaded, but the probelm is the slow processing for the sphere rotation... any help!

this is how i load the jpeg image in a seoarate method called once in the main method

void loadtexture()
{
    tex_2d[0] = SOIL_load_OGL_texture(
        "filename",
        SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,
        SOIL_FLAG_MIPMAPS);
    printf( "Image loaded successfully.. ");
    if(tex_2d[0]==0 ) {
        printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
    }
glBindTexture(GL_TEXTURE_2D, tex_2d[0]);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);//GL_NEAREST
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
}

and this is how i create my sphere and apply the texture to it

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex_2d[0]);
GLUquadricObj* esphere2 = gluNewQuadric();
gluQuadricTexture(esphere2, true);
gluQuadricNormals(esphere2, GLU_SMOOTH);
glEnable(GL_CULL_FACE);
gluSphere(esphere2, 4, 50, 50);
gluDeleteQuadric(esphere2); 
mallahyk
  • 25
  • 5
  • 1
    We will need to see your source code to be able to even hazard a guess at what is causing it to run slow. Can we see your render loop and the declaration of the sphere? Ideally a [minimal, complete and verifiable example](http://stackoverflow.com/help/mcve) – WearyWanderer Apr 27 '16 at 07:55
  • @mallahyk: Ugh, why post the code in comments? Just edit your question and paste it there. – datenwolf Apr 28 '16 at 22:17

1 Answers1

0

The problem is i tried using SOIL to load the image and it was successfully loaded, but the probelm is the slow processing for the sphere rotation

This reads as if you're re-loading the texture for each and every frame draw. Why would you do this? Just load the texture once and be done with it.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • yes i did that and its now much better.. thankss but when i now use the keyboard to rotate the textured sphere i have to rotate the texture itself and the image is not appearing with its full size. i'm using a jpg panoramic image of size 5276x2688, is there any constraint concerning the size of the image to be loaded using SOIL, as the rest of the sphere appears untextured while the rest of the image is not there as well.. – mallahyk Apr 28 '16 at 20:53
  • @mallahyk: OpenGL implementations have certain limitations on the maximum texture image size. You can query the actual limit using `glGetInteger(GL_MAX_TEXTURE_SIZE, …)`. I see in your "code comments" (why use comments, just paste it in your question; you can edit them) that you're using GL_SPHERE_MAP texture coordinate generation mode. Sphere map is a reflection mapping mode. What you probably want is explicitly stated texture coordinates, not some texture coordinate generation mode. – datenwolf Apr 28 '16 at 22:23
  • i want to create a virtual environment through the spherical mapping.. what do you think i can do ? – mallahyk Apr 28 '16 at 23:21
  • i didnt get it how can i get the maximum size that can be used as a texture ? – mallahyk Apr 29 '16 at 00:13
  • @mallahyk: So essentially you want to create a sky-sphere or a sky-dome i.e. a picture that surrounds the observer and serves as an infinitely far backdrop. Sphere maps are unsuitable for this because of the texture coordinate singularities they have. Either way the most straightforward thing is not to rely on fixed pipeline texture coordinate generation (this is an obsolete feature anyway) but by either implementing a proper geometry with explicitly stated texture coordinates, or implement a matching texture coordinate generation in the fragment shader (much easier). – datenwolf Apr 29 '16 at 08:05
  • @mallahyk: But this is outside the scope of this question and you should ask about how to implement a seamless background image (skydome, skysphere, skybox) in a separate question. – datenwolf Apr 29 '16 at 08:07