strange program.Use() behaviour

19 views
Skip to first unread message

Graeme H

unread,
Jan 28, 2013, 12:16:26 AM1/28/13
to go...@googlegroups.com
Hey all,

I've got a simple chunk of code that uses a simple texture program to draw a texture full screen. However, I'm running into some really weird behaviour with the OpenGL from github.com/go-gl/gl. If I call program.Use() once on init, everything works fine. However, I'm designing this to switch between multiple shaders, and so I thought I'd add program.Use() to the top of this specific drawing function, which gets called on every frame. If I do that, and nothing else, my app only draws a big white square instead of the texture / color stuff it's supposed to.

Here's my function:

func DrawTexture(t *glh.Texture, correctaspect bool) error {
// prg.Use()
gl.ActiveTexture(gl.TEXTURE0)
t.Bind(gl.TEXTURE_2D)

// draw!
gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)
if err := GLErrors(); err != nil {
// return errors.New("Error drawing texture: " + err.Error())
}

return GLErrors()
}

This gets called from the main app like so:

for glfw.WindowParam(glfw.Opened) == 1 {
if err = v.DrawTexture(tex, false); err != nil {
Logger.Fatalln(err)
}
glfw.SwapBuffers()
}

prg is the global variable for the shader program I'm using. So, prg.Use() once, works great, prg.Use() on every draw, just draws white.

Any ideas on how to debug this would be exceedingly welcome. ;)

Thanks,
Graeme H

Peter Waller

unread,
Jan 28, 2013, 2:39:05 PM1/28/13
to Graeme H, go...@googlegroups.com
It sounds to me as though what you're doing should work.

Obvious starting point, but I have to ask: are you ensuring that none of the functions are giving glErrors?

unit0x03

unread,
Jan 28, 2013, 2:52:56 PM1/28/13
to p...@pwaller.net, go...@googlegroups.com
Yes, but Piotr helped me debug my problem:

On creating the shader program, I'd put in := instead of straight =, so it was getting assigned to a new local variable instead of to the globally scoped one. I'd looked over the code a ton, I just didn't pick out the error.

It all works exactly like I'd expect now, so no bugs in the libs or anything. ;)

Thanks a ton for the help, guys. Always helps to have a second set of eyes on something.

Graeme

André Moraes

unread,
Jan 30, 2013, 6:25:11 AM1/30/13
to unit0x03, p...@pwaller.net, go...@googlegroups.com
> On creating the shader program, I'd put in := instead of straight =, so it
> was getting assigned to a new local variable instead of to the globally
> scoped one. I'd looked over the code a ton, I just didn't pick out the
> error.

Just a design tip, but, avoid using globals. Even on single threaded
applications.

--
André Moraes
http://amoraes.info
Reply all
Reply to author
Forward
0 new messages