Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

baldurk

gtkglext texture problem

This topic is 5166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
// 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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
yeh, that was my reason for doing it. I''m glad it helped.

However, necromancing an old topic just to say it helped is perhaps less useful..

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!