OK so I have a simple setup going on. Basically I am just drawing some textures and shapes. However sizing is going weird... let me show you how any maybe you can diagnose.
Basically everything is broken into components that work fine by themselves, however when together it is disastrous.
Case #1 Section of actual texture appears with an enlarged resolution in the bottom left corner.
glViewport(0, 0, GLsizei(width), GLsizei(height))
layer_shapes.begin()
glViewport(0, 0, GLsizei(width), GLsizei(height))
checkFades()
drawShapes()
layer_shapes.end()
drawTexture(layer_shapes, alpha: 0.0)
Case #2 Image appears enlarged and full screen
layer_shapes.begin()
checkFades()
drawShapes()
layer_shapes.end()
drawTexture(layer_shapes, alpha: 0.0)
Case #3 proving that texture drawing works by drawing to front buffer (I put a texture into a fbo and never drew to the fbo)
drawTexture(layer_shapes, alpha: 0.0)
Case #4 Proving that shape drawing works (This is what it should look like, except with an accumulation effect)
drawShapes()
(Please note discoloration is due to a debugging thing in the fragment shader, not an error)
In summary Cases 1 and 2 do not work as intended (they enlarge only part of the shape drawing and put it in the wrong proportion on the screen). Cases 3 and 4 show the individual complnents (drawing shapes, and drawing textures) working when everything is drawn to the front buffer without any 'glViewport' calls.
The desired behavior is that an image like case 4 would be drawn, however the image would be an accumulation of previous frames (Notice how i never clear the layer_shapes fbo) so the shapes (that are moving) would leave a trail. The proportions are just being weird!
And Incase you want to see it here is how I set up my texture fbo's. They get initialized and then have .load() called on them
class TextureBuffer {
var framebuffer:GLuint = 0
var tex:GLuint = 0
var old_fbo:GLint = 0
var w:GLsizei = 0
var h:GLsizei = 0
init(widthi: GLsizei = 0, heighti: GLsizei = 0)
{
w = widthi
h = heighti
}
func begin()
{
glGetIntegerv(GLenum(GL_FRAMEBUFFER_BINDING), &old_fbo)
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), framebuffer)
}
func checkStatus()
{
let status = glCheckFramebufferStatus(GLenum(GL_FRAMEBUFFER))
if (status != GLenum(GL_FRAMEBUFFER_COMPLETE))
{
print("DIDNT GO WELL WITH")
print(status)
}
}
func end()
{
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), GLenum(old_fbo))
}
func loadTexture(name: String, type: String) -> GLuint
{
var it:GLKTextureInfo = GLKTextureInfo()
let pic = UIImage(named: name + "." + type)!.CGImage
let path = NSBundle.mainBundle().pathForResource(name, ofType: type)
do
{
try it = GLKTextureLoader.textureWithContentsOfFile(path!, options: nil)
}
catch
{
do
{
//print("ERR Loading: " + path!)
try it = GLKTextureLoader.textureWithCGImage(pic!, options: nil)
}
catch
{
print("Error loading UIImage: " + pic.debugDescription)
it = GLKTextureInfo()
}
}
return it.name
}
func load(width: CGFloat?, height: CGFloat?)
{
if let lwidth = width
{
w = GLsizei(lwidth)
}
if let lheight = height
{
h = GLsizei(lheight)
}
glBindTexture(GLenum(GL_TEXTURE_2D), 0)
glGetIntegerv(GLenum(GL_FRAMEBUFFER_BINDING), &old_fbo)
glGenFramebuffers(1, &framebuffer)
tex = loadTexture("Black", type: "png")
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), framebuffer)
glBindTexture(GLenum(GL_TEXTURE_2D), tex)
//------>>>>glTexImage2D(GLenum(GL_TEXTURE_2D), 0, GL_RGBA, GLsizei(w), GLsizei(h), 0, GLenum(GL_RGBA), GLenum(GL_UNSIGNED_BYTE), nil)
glFramebufferTexture2D(GLenum(GL_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT0), GLenum(GL_TEXTURE_2D), tex, 0)
let status = glCheckFramebufferStatus(GLenum(GL_FRAMEBUFFER))
if (status != GLenum(GL_FRAMEBUFFER_COMPLETE))
{
print("DIDNT GO WELL WITH", width, " " , height)
print(status)
}
glBindFramebuffer(GLenum(GL_FRAMEBUFFER), GLenum(old_fbo))
}
}
A thought is there was a line near the end (I put an arrow pointing to it) that I had to remove to get the fbo to work properly. Previously the code worked fine, however it is not working fine now.
I do have a suspicion that since I have removed that line that caused nothing to work that the texture that is generated by it is the wrong size since the texture it is loading is of a non-device size. However I do not know why that call causes everything not to work.