// GtkGlExt init code
GdkGLConfig *glconfig =
gdk_gl_config_new_by_mode(GdkGLConfigMode(GDK_GL_MODE_RGB |
GDK_GL_MODE_DEPTH |
GDK_GL_MODE_DOUBLE));
if(!glconfig)
return 1;
widget = gtk_drawing_area_new();
if(!GTK_IS_WIDGET(widget))
{
g_print("Can''t create GtkDrawingArea widget\n");
return 1;
}
gtk_widget_set_size_request(widget, 640, 480);
gtk_widget_set_gl_capability(widget, glconfig, NULL, TRUE,
GDK_GL_RGBA_TYPE);
g_signal_connect_after(G_OBJECT (widget), "realize",
G_CALLBACK (init), this);
g_signal_connect(G_OBJECT (widget), "configure_event",
G_CALLBACK (reshape), this);
g_signal_connect(G_OBJECT (widget), "expose_event",
G_CALLBACK (draw), this);
g_signal_connect(G_OBJECT (widget), "visibility_notify_event",
G_CALLBACK (reshape), this);
gtk_idle_add_priority(GDK_PRIORITY_REDRAW,
(GtkFunction)idle,
widget);
//////////////////////////////////////////////////////////
// The GL init code
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glDisable(GL_BLEND);
glDisable(GL_STENCIL);
glDisable(GL_ALPHA_TEST);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//////////////////////////////////////////////////////
// I''m setting the texture manually to make sure it''s not my texture loading code that''s at fault. Neither file-loaded or this way works :/.
glGenTextures(1, &ID);
glBindTexture(GL_TEXTURE_2D, ID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
unsigned char data[48] = {255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0,
255, 0, 0, 0, 255, 0, 255, 0, 0, 255, 0, 0,
255, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 255,
255, 0, 0, 0, 255, 0, 255, 0, 0, 0, 0, 255};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 4, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
////////////////////////////////////////////////////////
// And finally my drawing code
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glEnable(GL_TEXTURE_2D);
glTranslatef(0.0f, 0.0f, -12.0f);
glBindTexture(GL_TEXTURE_2D, ID);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
All I see is a white quad in the middle of the widget. glColor3f can change it to red, but no texture appears.
If you want to see any more code I can paste any other relevant sections. I thought this was all the important code.
gtkglext texture problem
Hey. I have a gtk-2 app, and it''s working fine. I''ve put in a gtkglext widget, and that''s also working fine. I can render objects with colours etc.
However, I can''t render objects with textures.
I don''t know what I''m doing wrong. I''ve enabled texturing, and disabled virtually everything else that could be causing a problem. Blending, lighting, etc.
Here''s the relevant code:
I fixed it, at last.
In case anyone wants to know, you have to call gdk_gl_drawable_gl_begin() before setting up the texture, or it doesn''t do it.
In case anyone wants to know, you have to call gdk_gl_drawable_gl_begin() before setting up the texture, or it doesn''t do it.
Thanks. Just had the smae problem.
This just show how important it is to reply to ones own problems if you finds a solution :-)
Yours
Peter Poulsen
This just show how important it is to reply to ones own problems if you finds a solution :-)
Yours
Peter Poulsen
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement