On Mon, 2008-08-25 at 22:29 +0900, bobos26 wrote:
> Hi there.
> 
> I send you this E-mail to bag your help
> 
> I'm currently making widget(or custom actor) to draw sphere
> I use openGL library to draw sphere and use COGL library to map
> texture.
> I success to draw sphere but I cannt map the sphere with JPG image.
> I can see the sphere but mapping image is totally crashed.
> I thing there is something problems with vertex and texture
> positionning.
> so i tried to find that for 3 days. but i couldn't find that.
> i use normal JPG image and make source likes down there.
> 
> please what i have to fix~
> 
> -Source Image
> world
> 
> -Result
> 
> sphere
> (where is my beautiful Earth?)
> 
> 
> 
> 
> 
> - Make Arrays
> 
>     for( i = 0; i < p/2; ++i ){
>         theta1 = i * TWOPI / p - PIDIV2;
>         theta2 = (i + 1) * TWOPI / p - PIDIV2;
> 
>         for(j = 0; j <= p; ++j ){
>             theta3 = j * TWOPI / p;
> 
>             ex = cosf(theta2) * cosf(theta3);
>             ey = sinf(theta2);
>             ez = cosf(theta2) * sinf(theta3);
> 
>             array[polygon_index]     = ex*width;
>             polygon_index++;
>             
>             array[polygon_index]     = ey*width;
>             polygon_index++;
>             
>             array[polygon_index]     = ez*width;
>             polygon_index++;
> 
>             vertices[geo_index].x =
> CLUTTER_FLOAT_TO_FIXED((ex*width));
>             vertices[geo_index].y =
> CLUTTER_FLOAT_TO_FIXED((ey*width));
>             vertices[geo_index].z =
> CLUTTER_FLOAT_TO_FIXED((ez*width));
>             vertices[geo_index].tx =CLUTTER_FLOAT_TO_FIXED(
> j/(float)p);
>             vertices[geo_index].ty =CLUTTER_FLOAT_TO_FIXED((2*i
> +1)/(float)p);
>             geo_index++;
> 
>             ex = cosf(theta1) * cosf(theta3);
>             ey = sinf(theta1);
>             ez = cosf(theta1) * sinf(theta3);
> 
>             array[polygon_index]     = ex*width;
>             polygon_index++;
>             
>             array[polygon_index]     = ey*width;
>             polygon_index++;
>             
>             array[polygon_index]     = ez*width;
>             polygon_index++;
>             
>             vertices[geo_index].x
> =CLUTTER_FLOAT_TO_FIXED((ex*width));
>             vertices[geo_index].y
> =CLUTTER_FLOAT_TO_FIXED((ey*width));
>             vertices[geo_index].z
> =CLUTTER_FLOAT_TO_FIXED((ez*width));
>             vertices[geo_index].tx  =CLUTTER_FLOAT_TO_FIXED(
> j/(float)p);
>             vertices[geo_index].ty
> =CLUTTER_FLOAT_TO_FIXED(2*i/(float)p);
>             geo_index++;
>        }
>     }
> 
> 
> - Make Texture
>     priv->cogl_tex_id = cogl_texture_new_from_file ("worldmap.jpg", 0,
> FALSE,
>             COGL_PIXEL_FORMAT_ANY,
>             NULL);
You need to pass -1 in here for max_waste so that cogl will not slice
your texture up. This is a requirement of the cogl_texture_polygon call.
Also this would let you use cogl_texture_get_gl_texture
to pluck out a GL handle for the texture loaded by Cogl. (see more
below)

> 
>     cogl_texture_set_filters
> (priv->cogl_tex_id,CGL_NEAREST,CGL_NEAREST);
> 
> - Draw sphere and Mapping
> //-------------------------------------- Vertex draw
>     glEnableClientState(GL_VERTEX_ARRAY);
>     glVertexPointer   (3, GL_FLOAT, 0, array);    
>     glDrawArrays(GL_TRIANGLE_STRIP, 0, 930);

It looks like you are trying to emit geometry here without enabling
texturing. This step seems redundant looking at your next step where you
then use Cogl to emit textured geometry. (OpenGL/Clutter does not
separate the phases of emitting geometry and then painting that
geometry. With OpenGL it's more like you emit textured-geometry. Or
rather you glEnable (TEXTURE_2D) bind your texture and emit vertices
that include a position and texture coordinates)

> //----------------------------------------- Mapping
>     CoglTextureVertex verticess[4];
>     CoglTextureVertex tmp[3];
>     int l = 0;
>     int m = 0;
>     int n = 0;
>     int o = 0;
>     for (l = 0; l < 930; l++)
>     {
>         if (o != 0){
>             verticess[0] = verticess[2];
>             verticess[1] = verticess[3];
>             o = 0;
>         }else{
>             verticess[m] = vertices[l];
>         }
>         m = m +1;
>         printf("%d, ",m);
>         if(m == 4)
>         {
>             for (n = 0;n < 3;n++)
>             {
>                 if (n == 0)
>                 {
>                     tmp[n] = verticess[0];
>                 }else if(n ==1)
>                 {
>                     tmp[n] = verticess[1];
>                 }else if(n == 2)
>                 {
>                     tmp[n] = verticess[2];
>                 }
> 
>             }
>             cogl_texture_polygon (priv->cogl_tex_id, 3, tmp, FALSE);
>             for (n = 0;n < 3;n++)
>             {
>                 if (n == 0)
>                 {
>                     tmp[n] = verticess[2];
>                 }else if(n ==1)
>                 {
>                     tmp[n] = verticess[1];
>                 }else if(n == 2)
>                 {
>                     tmp[n] = verticess[3];
>                 }
>             }
>             cogl_texture_polygon (priv->cogl_tex_id, 3, tmp, FALSE);
>             m = 2;
>             o = 1;
>             printf(" | ");
>         }
>     }

Instead of using cogl_texture_polygon you could pull out the GL texture
ID from your cogl texture using cogl_texture_get_gl_texture so you can
bind it manually and glEnableClientState (GL_TEXTURE_COORD_ARRAY) before
calling glDrawElements. (NB, if you do this you should pass -1 for max
waste when calling cogl_texture_from_file so that cogl will not slice
the texture up.)

Cogl doesn't currently have an efficient mesh data type to allow
submitting geometry in the quite the fashion you desire. If you wanted
to be more portable though, you could try removing any manual GL calls
and just use cogl_texture_polygon.

Sorry I can't help with the details of the algorithms here. A cursory
glance suggests you are indeed generating texture coords between 0 and 1
which is also a requirement for cogl_texture_polygon.

kind regards,
- Robert

-- 
To unsubscribe send a mail to [EMAIL PROTECTED]

Reply via email to