LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-13-2008, 12:04 AM   #1
bonserk
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Rep: Reputation: 0
making clutter custom_actor problem.


hi there.

If somebody have any idea or answer.
please let me know!!

I just wanna make clutter custom_actor to draw sphere
so I use clutter tutorial named clutter_triangle.c
this file positioned in

/clutter/clutter-tutorial/examples/custom_actor$

and i just put some gl function to draw sphere and mapped that by texture mapping. after that, if i move mouse pointer over the spherem, this error massage fill the screen.

(./sphere:7863): Clutter-CRITICAL **: clutter_id_pool_lookup: assertion `id < id_pool->array->len' failed

so, i try to understand what is problem. and found if i dont use the functions for lighting and texture mapping like a

glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glEnable( GL_TEXTURE_2D );


, error massage is not appare.

i still don't know what i have to do
please help me~! please~!

this is the source
clutter-sphere.c
------------------------------------------------------------------------
#include "clutter-sphere.h"
#include "cogl/cogl.h"
#include <math.h>
#include <GL/gl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>


G_DEFINE_TYPE (ClutterSphere, clutter_sphere, CLUTTER_TYPE_ACTOR);

enum
{
PROP_0,

PROP_COLOR
};

#define CLUTTER_SPHERE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_SPHERE, ClutterSpherePrivate))

struct _ClutterSpherePrivate
{
ClutterColor color;
};

static void
renderSphere( float cx, float cy, float cz, float r, int p, int width )
{
const float TWOPI = 6.28318530717958f;
const float PIDIV2 = 1.57079632679489f;

float theta1 = 0.0;
float theta2 = 0.0;
float theta3 = 0.0;

float ex = 0.0f;
float ey = 0.0f;
float ez = 0.0f;

float px = 0.0f;
float py = 0.0f;
float pz = 0.0f;
int i,j;

if( r < 0 )
r = -r;
if( p < 0 )
p = -p;

if( p < 4 || r <= 0 ){
glBegin( GL_POINTS );
glVertex3f( cx, cy, cz );
glEnd();
return;
}

for( i = 0; i < p/2; ++i ){
theta1 = i * TWOPI / p - PIDIV2;
theta2 = (i + 1) * TWOPI / p - PIDIV2;

glBegin( GL_TRIANGLE_STRIP );
{
for(j = 0; j <= p; ++j ){
theta3 = j * TWOPI / p;

ex = cosf(theta2) * cosf(theta3);
ey = sinf(theta2);
ez = cosf(theta2) * sinf(theta3);
px = cx + r * ex;
py = cy + r * ey;
pz = cz + r * ez;

glNormal3f( ex*width, ey*width, ez*width );
glTexCoord2f( -(j/(float)p) , 2*(i+1)/(float)p );
glVertex3f( px*width, py*width, pz*width );

ex = cosf(theta1) * cosf(theta3);
ey = sinf(theta1);
ez = cosf(theta1) * sinf(theta3);
px = cx + r * ex;
py = cy + r * ey;
pz = cz + r * ez;

glNormal3f( ex*width, ey*width, ez*width );
glTexCoord2f( -(j/(float)p), 2*i/(float)p );
glVertex3f( px*width, py*width, pz*width );
}
}
glEnd();
}
}

static void
do_sphere_paint (ClutterActor *self, const ClutterColor *color)
{
ClutterSphere *sphere = CLUTTER_SPHERE(self);
//ClutterSpherePrivate *priv;
//sphere = CLUTTER_SPHERE(self);
//priv = sphere->priv;
guchar *texpix; // 픽셀 버퍼에서 읽어온 데이타
GdkPixbuf *pixbuf; // 픽셀 버퍼
GError *error = NULL;
GLuint g_textureID = 0;
ClutterGeometry geom;
clutter_actor_get_geometry (self, &geom);
//======================================================================
cogl_push_matrix();
glEnable( GL_DEPTH_TEST );
//======================================================================
//glEnable( GL_TEXTURE_2D );
pixbuf = gdk_pixbuf_new_from_file ("earth.bmp", &error);
texpix = gdk_pixbuf_get_pixels (pixbuf);
gint width = gdk_pixbuf_get_width (pixbuf);
gint height = gdk_pixbuf_get_height (pixbuf);
pixbuf = NULL;

glGenTextures( 1, &g_textureID );
glBindTexture( GL_TEXTURE_2D, g_textureID );

glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0,
GL_RGB, GL_UNSIGNED_BYTE, texpix);

//======================================================================
//glMatrixMode( GL_PROJECTION );
//glEnable( GL_LIGHTING );
//glEnable( GL_LIGHT0 );

float fAmbientColor[] = { 1.0f, 1.0f, 1.0f, 1.0f};
glLightfv( GL_LIGHT0, GL_AMBIENT, fAmbientColor );

float fDiffuseColor[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glLightfv( GL_LIGHT0, GL_DIFFUSE, fDiffuseColor );

float fSpecularColor[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv( GL_LIGHT0, GL_SPECULAR, fSpecularColor );

float fPosition[] = { -1.0f, -1.0f, 1.0f, 0.0f };
glLightfv( GL_LIGHT0, GL_POSITION, fPosition );

GLfloat ambient_lightModel[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glLightModelfv( GL_LIGHT_MODEL_AMBIENT, ambient_lightModel );
//======================================================================
//glMatrixMode( GL_MODELVIEW );
//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
glEnable( GL_NORMALIZE );

//glRotatef (45.0f, 0.0f, 1.0f, 0.0f);
renderSphere( 0.0f, 0.0f, 0.0f, 1.0f, 80, geom.width);
cogl_pop_matrix();
}

static void
clutter_sphere_paint (ClutterActor *self)
{
ClutterSphere *sphere = CLUTTER_SPHERE(self);
ClutterSpherePrivate *priv = sphere->priv;

/* Paint the sphere with the actor's color: */
ClutterColor color;
color.red = priv->color.red;
color.green = priv->color.green;
color.blue = priv->color.blue;
color.alpha = clutter_actor_get_opacity (self);

do_sphere_paint (self, &color);
}

static void
clutter_sphere_pick (ClutterActor *self, const ClutterColor *color)
{
/* Paint the sphere with the pick color, offscreen.
This is used by Clutter to detect the actor under the cursor
by identifying the unique color under the cursor. */
do_sphere_paint (self, color);
}

static void
clutter_sphere_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ClutterSphere *sphere = CLUTTER_SPHERE(object);

switch (prop_id)
{
case PROP_COLOR:
clutter_sphere_set_color (sphere, g_value_get_boxed (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

static void
clutter_sphere_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ClutterSphere *sphere = CLUTTER_SPHERE(object);
ClutterColor color;

switch (prop_id)
{
case PROP_COLOR:
clutter_sphere_get_color (sphere, &color);
g_value_set_boxed (value, &color);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}


static void
clutter_sphere_finalize (GObject *object)
{
G_OBJECT_CLASS (clutter_sphere_parent_class)->finalize (object);
}

static void
clutter_sphere_dispose (GObject *object)
{
G_OBJECT_CLASS (clutter_sphere_parent_class)->dispose (object);
}


static void
clutter_sphere_class_init (ClutterSphereClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);

/* Provide implementations for ClutterActor vfuncs: */
actor_class->paint = clutter_sphere_paint;
actor_class->pick = clutter_sphere_pick;

gobject_class->finalize = clutter_sphere_finalize;
gobject_class->dispose = clutter_sphere_dispose;
gobject_class->set_property = clutter_sphere_set_property;
gobject_class->get_property = clutter_sphere_get_property;

/**
* ClutterSphere:color:
*
* The color of the sphere.
*/
g_object_class_install_property (gobject_class,
PROP_COLOR,
g_param_spec_boxed ("color",
"Color",
"The color of the sphere",
CLUTTER_TYPE_COLOR,
G_PARAM_READABLE | G_PARAM_WRITABLE));

g_type_class_add_private (gobject_class, sizeof (ClutterSpherePrivate));
}

static void
clutter_sphere_init (ClutterSphere *self)
{
ClutterSpherePrivate *priv;

self->priv = priv = CLUTTER_SPHERE_GET_PRIVATE (self);

priv->color.red = 0xff;
priv->color.green = 0xff;
priv->color.blue = 0xff;
priv->color.alpha = 0xff;
}

/**
* clutter_sphere_new:
*
* Creates a new #ClutterActor with a rectangular shape.
*
* Return value: a new #ClutterActor
*/
ClutterActor*
clutter_sphere_new (void)
{
return g_object_new (CLUTTER_TYPE_SPHERE, NULL);
}

/**
* clutter_sphere_new_with_color:
* @color: a #ClutterColor
*
* Creates a new #ClutterActor with a rectangular shape
* and with @color.
*
* Return value: a new #ClutterActor
*/
ClutterActor *
clutter_sphere_new_with_color (const ClutterColor *color)
{
return g_object_new (CLUTTER_TYPE_SPHERE,
"color", color,
NULL);
}

/**
* clutter_sphere_get_color:
* @sphere: a #ClutterSphere
* @color: return location for a #ClutterColor
*
* Retrieves the color of @sphere.
*/
void
clutter_sphere_get_color (ClutterSphere *sphere,
ClutterColor *color)
{
ClutterSpherePrivate *priv;

g_return_if_fail (CLUTTER_IS_SPHERE (sphere));
g_return_if_fail (color != NULL);

priv = sphere->priv;

color->red = priv->color.red;
color->green = priv->color.green;
color->blue = priv->color.blue;
color->alpha = priv->color.alpha;
}

/**
* clutter_sphere_set_color:
* @sphere: a #ClutterSphere
* @color: a #ClutterColor
*
* Sets the color of @sphere.
*/
void
clutter_sphere_set_color (ClutterSphere *sphere,
const ClutterColor *color)
{
ClutterSpherePrivate *priv;

g_return_if_fail (CLUTTER_IS_SPHERE (sphere));
g_return_if_fail (color != NULL);

g_object_ref (sphere);

priv = sphere->priv;

priv->color.red = color->red;
priv->color.green = color->green;
priv->color.blue = color->blue;
priv->color.alpha = color->alpha;

clutter_actor_set_opacity (CLUTTER_ACTOR (sphere),
priv->color.alpha);

if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (sphere)))
clutter_actor_queue_redraw (CLUTTER_ACTOR (sphere));

g_object_notify (G_OBJECT (sphere), "color");
g_object_unref (sphere);
}

Last edited by bonserk; 08-13-2008 at 12:25 AM.
 
  


Reply

Tags
clutter, programing


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kmail clutter in home directory legalbeagle Linux - Desktop 0 09-10-2006 08:37 AM
Reducing package clutter? Randux Slackware 13 03-20-2006 09:12 AM
Cleaning up the clutter Fasn8n Ubuntu 10 03-01-2006 01:45 PM
uglyness and clutter eeried LQ Suggestions & Feedback 7 07-21-2005 09:27 PM
Fluxbox clutter intruptz Linux - Software 6 09-14-2003 02:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration