#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    39
    Rep Power
    2

    Screen turns blue when using textures (old function method)


    as the title states...

    I've just recently worked on getting textures working in my program...
    so far I've succeeded, however, once the textures actually appear, this happens:

    suddenly I'm blue... da be de da ba die (lol jk)

    anyways...
    so I've followed the nehe tutorials enabling GL_TEXTURE_2D and such...

    here's the image initialization code:
    python Code:
     
        #define textures here
        __GL.glPixelStorei(__GL.GL_UNPACK_ALIGNMENT,1)
        for Name,W,H,Pixels,Colors in Libs[7]:
            image = bytearray()
            if len(Colors)==0:
                Format = len(Pixels[0])-1 #I, IA, RGB, or RGBA format
                for IRAGBA in Pixels: image += bytearray(IRAGBA)
            else:
                Format = len(Colors[0])-1 #I, IA, RGB, or RGBA format
                for I in Pixels: image += bytearray(Colors[I])
     
            __GL_TEX[Name] = __GL.glGenTextures(1)
            __GL.glPixelStorei(__GL.GL_UNPACK_ALIGNMENT,1)
            __GL.glTexImage2D(__GL.GL_TEXTURE_2D, 0, 3, W, H, 0, [__GL.GL_LUMINANCE,__GL.GL_LUMINANCE_ALPHA,__GL.GL_RGB,__GL.GL_RGBA][Format], __GL.GL_UNSIGNED_BYTE, str(image))


    and here's the part where the textures from the material call and use the images:
    python Code:
     
                SDType,SDName,SDData1,SDData2=Sub_Data
     
                if SDType=="_Mesh":
                    __GL.glLineWidth(1.0)
     
                    MaterialName,AddOn,MatColors,Textures,R1,R2 = Libs[4][SDData1] if type(SDData1)==int else [
                        "UMC_Def_Mat", '', [[1.0,1.0,1.0,1.0],[1.0,1.0,1.0,1.0],[0.5,0.5,0.5,1.0],[0.0,0.0,0.0,0.0],25.0], [], [], []
                        ]
     
                    MAR,MAG,MAB,MAA = MatColors[0] #Ambient
                    MDR,MDG,MDB,MDA = MatColors[1] #Diffuse
                    MSR,MSG,MSB,MSA = MatColors[2] #Specular
                    MER,MEG,MEB,MEA = MatColors[3] #Emmisive
                    MSV = MatColors[4] #Shininess
     
                    #call from pre-defined textures here
                    for TexID in Textures:
                        TexName,TexParams,Reserved,ImageName = Libs[6][TexID]
     
                        # Apply Texture(s)
                        __GL.glBindTexture(__GL.GL_TEXTURE_2D, __GL_TEX[ImageName] )
     
                        #__GL.glTexEnvf(__GL.GL_TEXTURE_ENV, __GL.GL_TEXTURE_ENV_MODE, __GL.GL_MODULATE)
                        __GL.glTexParameterf(__GL.GL_TEXTURE_2D, __GL.GL_TEXTURE_WRAP_S, __GL.GL_CLAMP)
                        __GL.glTexParameterf(__GL.GL_TEXTURE_2D, __GL.GL_TEXTURE_WRAP_T, __GL.GL_CLAMP)
                        __GL.glTexParameterf(__GL.GL_TEXTURE_2D, __GL.GL_TEXTURE_WRAP_S, __GL.GL_REPEAT)
                        __GL.glTexParameterf(__GL.GL_TEXTURE_2D, __GL.GL_TEXTURE_WRAP_T, __GL.GL_REPEAT)
                        __GL.glTexParameterf(__GL.GL_TEXTURE_2D, __GL.GL_TEXTURE_MAG_FILTER, __GL.GL_NEAREST)
                        __GL.glTexParameterf(__GL.GL_TEXTURE_2D, __GL.GL_TEXTURE_MIN_FILTER, __GL.GL_NEAREST)
                        __GL.glTexEnvf(__GL.GL_TEXTURE_ENV, __GL.GL_TEXTURE_ENV_MODE, __GL.GL_MODULATE)
     
                    Verts,Normals,Colors,UVs,Weights,Primitives=SDData2


    any info that could help is greatly appreciated.

    also, if I'm not structuring something correct in my format, please let me know.
    my format is really nothing more than the Libs var seen in the code which is a strucured list of lists.
    this format is a common interface format to support what Blender, 3DS, XSI, SketchUp, Steam, and more can support.

    thank you
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,856
    Rep Power
    481
    Do you have another program that uses gl?
    What happens to your screen when you run it?
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    39
    Rep Power
    2
    Originally Posted by b49P23TIvg
    Do you have another program that uses gl?
    What happens to your screen when you run it?
    not sure if I have it anymore, but it was a cube that would run along a textured floor.
    that one worked perfectly... >_>

    for more info I guess I should mention I'm using PyGame (SDL)

    perhapse I should post the initialization function as well...

    or actually, here's what's enabled (re enabled during video resize)
    python Code:
        __GL.glEnable(__GL.GL_TEXTURE_2D)
        __GL.glEnable(__GL.GL_DEPTH_TEST)
        __GL.glDepthFunc(__GL.GL_LEQUAL)
        __GL.glEnable(__GL.GL_LIGHTING)
        __GL.glEnable(__GL.GL_LIGHT0)
        __GL.glEnable(__GL.GL_NORMALIZE) #scale normals when model is scaled
        __GL.glDisable(__GL.GL_BLEND) #disabled for models
        __GL.glBlendFunc(__GL.GL_SRC_ALPHA, __GL.GL_ONE_MINUS_SRC_ALPHA)


    and just to note...
    the GUI is a completely seperate interface, meant to be pluggable (though that failed)
    everything drawn behind the GUI is cleared from the depth buffer before the GUI is drawn...

    if you need, I can make a src build and send you the SES file containing the model displayed in the image :/

    the screen doesn't turn blue until the model is imported.
    (more like until the texture displays, since other models (no textures yet) can import just fine)


    the code in the main post is actually used in building a display list which is then drawn on the screen
    (since animation isn't possible in this build)

    EDIT:
    to also mention, I've not enabled alpha testing...
    the image has an alpha of 128 as an RGBA image

    could that be what's affecting it??

    pixels are organized as str(bytearray([int R,G,B,A ])) with the GL_RGBA pixel attribute in glTexImage2D
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    39
    Rep Power
    2
    here's an update:
    I only limited texturing to be enabled ONLY when the display list for the model is being generated:


    so that solves half the problem... heh

    I'm not sure why it's blue though...
    this is the same exact thing I did to that example I mentioned before...

    could it have something to do with RGB(A) maybe??
    (since transparency doesn't seem to be getting applied) >_>

    would you like me to post the full code block??
    (could get a bit large, but at least it's scrollable)
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    39
    Rep Power
    2
    I FIGURED IT OUT... XP

    the blue-ish color is correct... :P
    R,G,B,A = 64, 128, 255, 128

    and the reason it was applying to the GUI was cause the GUI is drawn after the model, along with the grid and everything else.
    (textures were enabled for them)

    so the texture was being applied to the existing color of all objects,
    and with those objects having no UV's, they were only using the first pixel of the texture.

    as for the 2nd image, it's working perfectly
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    39
    Rep Power
    2
    can I request deletion of this topic

    as it turns out it was just me being an idiot XD
    (I wasn't disabling GL_TEXTURE_2D when I didn't need it)

    thanx

IMN logo majestic logo threadwatch logo seochat tools logo