Re: [GtkGLExt] gtkglext-list Digest, Vol 53, Issue 1



I am sorry to bother with the same problem but I could not fix it, so I had to modify the program. 

Earlier I mentioned a problem in implementing the share-lists.c example in Windows Vista and then when you run the example sends me the following errors 

(share_list.exe: 2108): GtkGLExt-WARNING **: can not create GdkGLContext 

(share_list.exe: 2108): GdkGLExt-CRITICAL **: file gdkglwindow-win32.c: line 297 
(gdk_gl_window_impl_win32_make_context_current): assertion `GDK_IS_GL_CONTEXT_IM 
PL_WIN32 (glcontext) 'failed 

etc…

The problem is that I can not share the context of different opengl viewport, so I can not use a texture defined in a viewport or a list of drawing in another viewport. 

when the program execute the line 

   GdkGLContext * glcontext = gtk_widget_get_gl_context (widget); 
  
In the following function.

static void realize_main (GtkWidget * widget, GLfloat * light_diffuse); 
static void realize_sub (GtkWidget * widget, GLfloat * light_diffuse); 
static void realize_sub (GtkWidget * widget, GLfloat * light_diffuse); 
static gboolean configure_event (GtkWidget * widget, GdkEventConfigure * event, gpointer data); 
static gboolean expose_event (GtkWidget * widget, GdkEventExpose * event, gpointer data); 

Sends me the following error. 

(share_list.exe: 2108): GtkGLExt-WARNING **: can not create GdkGLContext 

because I can not get the context of opengl then glcontext = NULL; and when execute the line. 
  
if (! gdk_gl_drawable_gl_begin (gldrawable, glcontext)) 

I get the following error 

(share_list.exe: 2108): GdkGLExt-CRITICAL **: file gdkglwindow-win32.c: line 297 
(gdk_gl_window_impl_win32_make_context_current): assertion `GDK_IS_GL_CONTEXT_IM 
PL_WIN32 (glcontext) 'failed 

So the condition is false and does not draw the viewport, for that reason I can only see a viewport and the other two do not show anything, 

Thought the problem was that I can not get in the context of opengl with gtk_widget_get_gl_context then I use global variable for manager the context, but doing this I can not show any viewport.

Then my next solution was to create a list drawing for each viewport, so it would also have to do the same with the textures and because I can not share between viewports, the code as follows

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

#include <stdlib.h>
#include <gtk/gtk.h>
#include <gtk/gtkgl.h>

#ifdef G_OS_WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif

#include <GL/gl.h>
#include <GL/glu.h>

static GLfloat red[]    = {1.0, 0.0, 0.0, 1.0};
static GLfloat yellow[] = {1.0, 1.0, 0.0, 1.0};
static GLfloat green[]  = {0.0, 1.0, 0.0, 1.0};

GdkGLContext *gCont;

static void init_gl (GLfloat *light_diffuse){
	static GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};

	glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
	glLightfv (GL_LIGHT0, GL_POSITION, light_position);
	glEnable (GL_LIGHTING);
	glEnable (GL_LIGHT0);
	glEnable (GL_DEPTH_TEST);

	glClearColor (1.0, 1.0, 1.0, 1.0);
	glClearDepth (1.0);

	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	gluPerspective (40.0, 1.0, 1.0, 10.0);

	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();
	gluLookAt (0.0, 0.0, 3.0,
		0.0, 0.0, 0.0,
		0.0, 1.0, 0.0);
	glTranslatef (0.0, 0.0, -3.0);
}

static void realize_main (GtkWidget *widget, GLfloat   *light_diffuse){

	GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

	GLUquadricObj *qobj;

	if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
	//if (!gdk_gl_drawable_gl_begin (gldrawable, gCont))
		return;

	qobj = gluNewQuadric ();
	gluQuadricDrawStyle (qobj, GLU_FILL);
	glNewList (1, GL_COMPILE);
	gluSphere (qobj, 1.0, 20, 20);
	glEndList ();

	init_gl (light_diffuse);

	gdk_gl_drawable_gl_end (gldrawable);

}

static void realize_sub (GtkWidget *widget, GLfloat   *light_diffuse){

	GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

	if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
	//if (!gdk_gl_drawable_gl_begin (gldrawable, gCont))
		return;

	init_gl (light_diffuse);

	gdk_gl_drawable_gl_end (gldrawable);

}

static gboolean configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer data){

	GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

	if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
	//if (!gdk_gl_drawable_gl_begin (gldrawable, gCont))
		return FALSE;

	glViewport (0, 0,
		widget->allocation.width, widget->allocation.height);

	gdk_gl_drawable_gl_end (gldrawable);

	return TRUE;
}

static gboolean expose_event (GtkWidget *widget,  GdkEventExpose *event, gpointer data){

	GdkGLContext *glcontext = gtk_widget_get_gl_context (widget);
	GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget);

	if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext))
	//if (!gdk_gl_drawable_gl_begin (gldrawable, gCont))
		return FALSE;

	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glCallList (1);

	if (gdk_gl_drawable_is_double_buffered (gldrawable))
		gdk_gl_drawable_swap_buffers (gldrawable);
	else
		glFlush ();

	gdk_gl_drawable_gl_end (gldrawable);

	return TRUE;
}

int main (int argc, char *argv[]){

	GdkGLConfig *glconfig;
	GdkGLContext *glcontext;

	GtkWidget *window;
	GtkWidget *vbox;
	GtkWidget *drawing_area;
	GtkWidget *button;

	gtk_init (&argc, &argv);

	gtk_gl_init (&argc, &argv);

	glconfig = gdk_gl_config_new_by_mode (static_cast<GdkGLConfigMode>(GDK_GL_MODE_RGB|GDK_GL_MODE_DEPTH|GDK_GL_MODE_DOUBLE));
	if (glconfig == NULL){
		g_print ("*** Cannot find the double-buffered visual.\n");
		g_print ("*** Trying single-buffered visual.\n");

		glconfig = gdk_gl_config_new_by_mode (static_cast<GdkGLConfigMode>(GDK_GL_MODE_RGB|GDK_GL_MODE_DEPTH));
		if (glconfig == NULL){
			g_print ("*** No appropriate OpenGL-capable visual found.\n");
			exit (1);
		}
	}

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (window), "share-lists");

	gtk_container_set_reallocate_redraws (GTK_CONTAINER (window), TRUE);
	gtk_container_set_border_width (GTK_CONTAINER (window), 10);

	g_signal_connect (G_OBJECT (window), "delete_event",G_CALLBACK (gtk_main_quit), NULL);

	vbox = gtk_vbox_new (FALSE, 10);
	gtk_container_add (GTK_CONTAINER (window), vbox);
	gtk_widget_show (vbox);

	drawing_area = gtk_drawing_area_new ();
	gtk_widget_set_size_request (drawing_area, 120, 120);

	gtk_widget_set_gl_capability (drawing_area,
		glconfig,
		NULL,
		TRUE,
		GDK_GL_RGBA_TYPE);

	g_signal_connect_after (G_OBJECT (drawing_area), "realize",	G_CALLBACK (realize_main), red);
	g_signal_connect (G_OBJECT (drawing_area), "configure_event",G_CALLBACK (configure_event), NULL);
	g_signal_connect (G_OBJECT (drawing_area), "expose_event",G_CALLBACK (expose_event), NULL);

	gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);

	gtk_widget_show (drawing_area);

	gtk_widget_realize (drawing_area);
	glcontext = gtk_widget_get_gl_context (drawing_area);
	gCont = glcontext;

	drawing_area = gtk_drawing_area_new ();
	gtk_widget_set_size_request (drawing_area, 120, 120);

	gtk_widget_set_gl_capability (drawing_area,
		glconfig,
		NULL,//glcontext, /* share_list */
		TRUE,
		GDK_GL_RGBA_TYPE);


	//g_signal_connect_after (G_OBJECT (drawing_area), "realize",	G_CALLBACK (realize_sub), yellow);
	g_signal_connect_after (G_OBJECT (drawing_area), "realize",	G_CALLBACK (realize_main), yellow);
	g_signal_connect (G_OBJECT (drawing_area), "configure_event",G_CALLBACK (configure_event), NULL);
	g_signal_connect (G_OBJECT (drawing_area), "expose_event",G_CALLBACK (expose_event), NULL);

	gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);

	gtk_widget_show (drawing_area);

	drawing_area = gtk_drawing_area_new ();
	gtk_widget_set_size_request (drawing_area, 120, 120);

	gtk_widget_set_gl_capability (drawing_area,
		glconfig,
		NULL,//glcontext, /* share_list */
		TRUE,
		GDK_GL_RGBA_TYPE);

	//g_signal_connect_after (G_OBJECT (drawing_area), "realize",	G_CALLBACK (realize_sub), green);
	g_signal_connect_after (G_OBJECT (drawing_area), "realize",	G_CALLBACK (realize_main), green);
	g_signal_connect (G_OBJECT (drawing_area), "configure_event",G_CALLBACK (configure_event), NULL);
	g_signal_connect (G_OBJECT (drawing_area), "expose_event",G_CALLBACK (expose_event), NULL);

	gtk_box_pack_start (GTK_BOX (vbox), drawing_area, TRUE, TRUE, 0);

	gtk_widget_show (drawing_area);

	button = gtk_button_new_with_label ("Quit");

	g_signal_connect (G_OBJECT (button), "clicked",	G_CALLBACK (gtk_main_quit), NULL);

	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

	gtk_widget_show (button);

	gtk_widget_show (window);

	gtk_main ();

	return 0;
}

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

But this is a bad solution, since it is much waste of memory, if anyone knows how to solve this problem could help me?.

Thank you very much.


__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.com.mx/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]