Thread: [PyOpenGL-Users] OpenGL textures
Brought to you by:
mcfletch
From: altern <al...@gm...> - 2007-03-29 08:25:42
|
hi I am trying to translate a pygame+opengl application to wx+opengl. And I am stuck at the function to import images to create OpenGL textures. I already asked for help on the wxpython list, but nobody seemed to be interested on my problem, so i thought there might be some wx-pyopengl users in the pyopengl list. This is the pygame code: surface = pygame.image.load(path) if surface.get_alpha is None: surface = surface.convert() else: surface = surface.convert_alpha() bin = pygame.image.tostring(surface, "RGBA", 1) w, h = surface.get_width(), surface.get_height() textid = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, textid) gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bin) ... and so on ... and this is the wx code i am using : image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) bin = image.ConvertToBitmap() w,h = image.GetWidth(), image.GetHeight() textid = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, textid) gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bin) ... etc ... It doesnt crash but the texture that OpenGL displays in not at all the image i am importing but some weird random colors. I guess this is the bit that i am missing, since printing "image.ConvertToBitmap()" returns a wxBitmap instance and not the image data bin = pygame.image.tostring(surface, "RGBA", 1) I have been trying to find out how to access the data an looking for examples on the net but did not find anything. any tips? thanks! enrike |
From: Andrew W. <and...@al...> - 2007-03-29 13:30:39
|
Hello, You may want to try, bin = image.GetData() Thanks andrew On 3/29/07, altern <al...@gm...> wrote: > > hi > > I am trying to translate a pygame+opengl application to wx+opengl. And I > am stuck at the function to import images to create OpenGL textures. > > I already asked for help on the wxpython list, but nobody seemed to be > interested on my problem, so i thought there might be some wx-pyopengl > users in the pyopengl list. > > This is the pygame code: > > surface = pygame.image.load(path) > if surface.get_alpha is None: > surface = surface.convert() > else: > surface = surface.convert_alpha() > bin = pygame.image.tostring(surface, "RGBA", 1) > w, h = surface.get_width(), surface.get_height() > textid = glGenTextures(1) > glBindTexture(GL_TEXTURE_2D, textid) > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bin) > ... and so on ... > > and this is the wx code i am using : > > image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) > bin = image.ConvertToBitmap() > w,h = image.GetWidth(), image.GetHeight() > textid = glGenTextures(1) > glBindTexture(GL_TEXTURE_2D, textid) > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, bin) > ... etc ... > > It doesnt crash but the texture that OpenGL displays in not at all the > image i am importing but some weird random colors. I guess this is the > bit that i am missing, since printing "image.ConvertToBitmap()" returns > a wxBitmap instance and not the image data > bin = pygame.image.tostring(surface, "RGBA", 1) > > I have been trying to find out how to access the data an looking for > examples on the net but did not find anything. > > any tips? thanks! > > enrike > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > |
From: altern <al...@gm...> - 2007-03-29 17:27:16
|
thanks andrew, i dont know how i did not find this myself, i was looking in wxBitmap class for this type of function. still i dont get the images properly displayed. I can see it has similar colors as the original but it is heavily pixelated. Is there any difference in the format of the image data array itself between wx and pygame? Andrew Wilson(e)k dio: > Hello, > You may want to try, > > bin = image.GetData() > > > Thanks > andrew > > > > On 3/29/07, *altern* < al...@gm... <mailto:al...@gm...>> wrote: > > hi > > I am trying to translate a pygame+opengl application to wx+opengl. > And I > am stuck at the function to import images to create OpenGL textures. > > I already asked for help on the wxpython list, but nobody seemed to be > interested on my problem, so i thought there might be some wx-pyopengl > users in the pyopengl list. > > This is the pygame code: > > surface = pygame.image.load(path) > if surface.get_alpha is None: > surface = surface.convert() > else: > surface = surface.convert_alpha () > bin = pygame.image.tostring(surface, "RGBA", 1) > w, h = surface.get_width(), surface.get_height() > textid = glGenTextures(1) > glBindTexture(GL_TEXTURE_2D, textid) > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, > bin) > ... and so on ... > > and this is the wx code i am using : > > image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) > bin = image.ConvertToBitmap() > w,h = image.GetWidth(), image.GetHeight() > textid = glGenTextures(1) > glBindTexture(GL_TEXTURE_2D, textid) > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, > bin) > ... etc ... > > It doesnt crash but the texture that OpenGL displays in not at all the > image i am importing but some weird random colors. I guess this is the > bit that i am missing, since printing "image.ConvertToBitmap()" returns > a wxBitmap instance and not the image data > bin = pygame.image.tostring(surface, "RGBA", 1) > > I have been trying to find out how to access the data an looking for > examples on the net but did not find anything. > > any tips? thanks! > > enrike > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net <http://pyopengl.sourceforge.net> > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > <mailto:PyO...@li...> > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > |
From: Matthew M. <mj...@ms...> - 2007-03-29 17:35:40
|
Doesn't image.GetData() return RGB, and not RGBA, data? On 3/29/07, altern <al...@gm...> wrote: > > thanks andrew, i dont know how i did not find this myself, i was looking > in > wxBitmap class for this type of function. > still i dont get the images properly displayed. I can see it has similar > colors as the original but it is heavily pixelated. Is there any > difference in the format of the image data array itself between wx and > pygame? > > Andrew Wilson(e)k dio: > > Hello, > > You may want to try, > > > > bin = image.GetData() > > > > > > Thanks > > andrew > > > > > > > > On 3/29/07, *altern* < al...@gm... <mailto:al...@gm...>> > wrote: > > > > hi > > > > I am trying to translate a pygame+opengl application to wx+opengl. > > And I > > am stuck at the function to import images to create OpenGL textures. > > > > I already asked for help on the wxpython list, but nobody seemed to > be > > interested on my problem, so i thought there might be some > wx-pyopengl > > users in the pyopengl list. > > > > This is the pygame code: > > > > surface = pygame.image.load(path) > > if surface.get_alpha is None: > > surface = surface.convert() > > else: > > surface = surface.convert_alpha () > > bin = pygame.image.tostring(surface, "RGBA", 1) > > w, h = surface.get_width(), surface.get_height() > > textid = glGenTextures(1) > > glBindTexture(GL_TEXTURE_2D, textid) > > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, > > bin) > > ... and so on ... > > > > and this is the wx code i am using : > > > > image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) > > bin = image.ConvertToBitmap() > > w,h = image.GetWidth(), image.GetHeight() > > textid = glGenTextures(1) > > glBindTexture(GL_TEXTURE_2D, textid) > > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, > > bin) > > ... etc ... > > > > It doesnt crash but the texture that OpenGL displays in not at all > the > > image i am importing but some weird random colors. I guess this is > the > > bit that i am missing, since printing "image.ConvertToBitmap()" > returns > > a wxBitmap instance and not the image data > > bin = pygame.image.tostring(surface, "RGBA", 1) > > > > I have been trying to find out how to access the data an looking for > > examples on the net but did not find anything. > > > > any tips? thanks! > > > > enrike > > > > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to > > share your > > opinions on IT & business topics through brief surveys-and earn cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > < > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > > _______________________________________________ > > PyOpenGL Homepage > > http://pyopengl.sourceforge.net <http://pyopengl.sourceforge.net> > > _______________________________________________ > > PyOpenGL-Users mailing list > > PyO...@li... > > <mailto:PyO...@li...> > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > |
From: altern <al...@gm...> - 2007-03-29 17:50:54
|
you are right i just discovered that. I can see as well that there is a way to get the alpha info image.GetAlpha() but i am not sure how to use this two different types of data to construct a valid opengl texture with alpha. Matthew Morris(e)k dio: > Doesn't image.GetData() return RGB, and not RGBA, data? > > On 3/29/07, *altern* <al...@gm... <mailto:al...@gm...>> wrote: > > thanks andrew, i dont know how i did not find this myself, i was > looking in > wxBitmap class for this type of function. > still i dont get the images properly displayed. I can see it has similar > colors as the original but it is heavily pixelated. Is there any > difference in the format of the image data array itself between wx and > pygame? > > Andrew Wilson(e)k dio: > > Hello, > > You may want to try, > > > > bin = image.GetData() > > > > > > Thanks > > andrew > > > > > > > > On 3/29/07, *altern* < al...@gm... > <mailto:al...@gm...> <mailto:al...@gm... > <mailto:al...@gm...>>> wrote: > > > > hi > > > > I am trying to translate a pygame+opengl application to > wx+opengl. > > And I > > am stuck at the function to import images to create OpenGL > textures. > > > > I already asked for help on the wxpython list, but nobody > seemed to be > > interested on my problem, so i thought there might be some > wx-pyopengl > > users in the pyopengl list. > > > > This is the pygame code: > > > > surface = pygame.image.load(path) > > if surface.get_alpha is None: > > surface = surface.convert () > > else: > > surface = surface.convert_alpha () > > bin = pygame.image.tostring(surface, "RGBA", 1) > > w, h = surface.get_width(), surface.get_height() > > textid = glGenTextures(1) > > glBindTexture(GL_TEXTURE_2D, textid) > > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, > GL_UNSIGNED_BYTE, > > bin) > > ... and so on ... > > > > and this is the wx code i am using : > > > > image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) > > bin = image.ConvertToBitmap() > > w,h = image.GetWidth(), image.GetHeight() > > textid = glGenTextures(1) > > glBindTexture(GL_TEXTURE_2D, textid) > > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, > GL_UNSIGNED_BYTE, > > bin) > > ... etc ... > > > > It doesnt crash but the texture that OpenGL displays in not > at all the > > image i am importing but some weird random colors. I guess > this is the > > bit that i am missing, since printing > "image.ConvertToBitmap()" returns > > a wxBitmap instance and not the image data > > bin = pygame.image.tostring(surface, "RGBA", 1) > > > > I have been trying to find out how to access the data an > looking for > > examples on the net but did not find anything. > > > > any tips? thanks! > > > > enrike > > > > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the > chance to > > share your > > opinions on IT & business topics through brief surveys-and > earn cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > > > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>> > > _______________________________________________ > > PyOpenGL Homepage > > http://pyopengl.sourceforge.net <http://pyopengl.sourceforge.net> > > _______________________________________________ > > PyOpenGL-Users mailing list > > PyO...@li... > <mailto:PyO...@li...> > > <mailto: PyO...@li... > <mailto:PyO...@li...>> > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > <mailto:PyO...@li...> > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > ------------------------------------------------------------------------ > > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |
From: Matthew M. <mj...@ms...> - 2007-03-29 18:01:18
|
Maybe make a new buffer: RGB_RGB_RGB_..... and fill in the blanks with the data from GetAlpha(). But there might be a better way, who knows. -Matt On 3/29/07, altern <al...@gm...> wrote: > > you are right i just discovered that. I can see as well that there is a > way to get the alpha info > image.GetAlpha() > but i am not sure how to use this two different types of data to > construct a valid opengl texture with alpha. > > Matthew Morris(e)k dio: > > Doesn't image.GetData() return RGB, and not RGBA, data? > > > > On 3/29/07, *altern* <al...@gm... <mailto:al...@gm...>> > wrote: > > > > thanks andrew, i dont know how i did not find this myself, i was > > looking in > > wxBitmap class for this type of function. > > still i dont get the images properly displayed. I can see it has > similar > > colors as the original but it is heavily pixelated. Is there any > > difference in the format of the image data array itself between wx > and > > pygame? > > > > Andrew Wilson(e)k dio: > > > Hello, > > > You may want to try, > > > > > > bin = image.GetData() > > > > > > > > > Thanks > > > andrew > > > > > > > > > > > > On 3/29/07, *altern* < al...@gm... > > <mailto:al...@gm...> <mailto:al...@gm... > > <mailto:al...@gm...>>> wrote: > > > > > > hi > > > > > > I am trying to translate a pygame+opengl application to > > wx+opengl. > > > And I > > > am stuck at the function to import images to create OpenGL > > textures. > > > > > > I already asked for help on the wxpython list, but nobody > > seemed to be > > > interested on my problem, so i thought there might be some > > wx-pyopengl > > > users in the pyopengl list. > > > > > > This is the pygame code: > > > > > > surface = pygame.image.load(path) > > > if surface.get_alpha is None: > > > surface = surface.convert () > > > else: > > > surface = surface.convert_alpha () > > > bin = pygame.image.tostring(surface, "RGBA", 1) > > > w, h = surface.get_width(), surface.get_height() > > > textid = glGenTextures(1) > > > glBindTexture(GL_TEXTURE_2D, textid) > > > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, > > GL_UNSIGNED_BYTE, > > > bin) > > > ... and so on ... > > > > > > and this is the wx code i am using : > > > > > > image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) > > > bin = image.ConvertToBitmap() > > > w,h = image.GetWidth(), image.GetHeight() > > > textid = glGenTextures(1) > > > glBindTexture(GL_TEXTURE_2D, textid) > > > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, > > GL_UNSIGNED_BYTE, > > > bin) > > > ... etc ... > > > > > > It doesnt crash but the texture that OpenGL displays in not > > at all the > > > image i am importing but some weird random colors. I guess > > this is the > > > bit that i am missing, since printing > > "image.ConvertToBitmap()" returns > > > a wxBitmap instance and not the image data > > > bin = pygame.image.tostring(surface, "RGBA", 1) > > > > > > I have been trying to find out how to access the data an > > looking for > > > examples on the net but did not find anything. > > > > > > any tips? thanks! > > > > > > enrike > > > > > > > > > > > > ------------------------------------------------------------------------- > > > Take Surveys. Earn Cash. Influence the Future of IT > > > Join SourceForge.net's Techsay panel and you'll get the > > chance to > > > share your > > > opinions on IT & business topics through brief surveys-and > > earn cash > > > > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > < > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > > > > > < > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > < > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > >> > > > _______________________________________________ > > > PyOpenGL Homepage > > > http://pyopengl.sourceforge.net < > http://pyopengl.sourceforge.net> > > > _______________________________________________ > > > PyOpenGL-Users mailing list > > > PyO...@li... > > <mailto:PyO...@li...> > > > <mailto: PyO...@li... > > <mailto:PyO...@li...>> > > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > > > > > > > > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to > > share your > > opinions on IT & business topics through brief surveys-and earn cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > < > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > > _______________________________________________ > > PyOpenGL Homepage > > http://pyopengl.sourceforge.net > > _______________________________________________ > > PyOpenGL-Users mailing list > > PyO...@li... > > <mailto:PyO...@li...> > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > > > > ------------------------------------------------------------------------ > > > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > > opinions on IT & business topics through brief surveys-and earn cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > > > > ------------------------------------------------------------------------ > > > > _______________________________________________ > > PyOpenGL Homepage > > http://pyopengl.sourceforge.net > > _______________________________________________ > > PyOpenGL-Users mailing list > > PyO...@li... > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > |
From: Andrew W. <and...@al...> - 2007-03-29 18:19:34
|
You may want to give PIL a shot. http://www.pythonware.com/products/pil/ Thanks Andrew On 3/29/07, Matthew Morris <mj...@ms...> wrote: > > Maybe make a new buffer: RGB_RGB_RGB_..... and fill in the blanks with > the data from GetAlpha(). But there might be a better way, who knows. > > -Matt > > On 3/29/07, altern <al...@gm...> wrote: > > > > you are right i just discovered that. I can see as well that there is a > > way to get the alpha info > > image.GetAlpha() > > but i am not sure how to use this two different types of data to > > construct a valid opengl texture with alpha. > > > > Matthew Morris(e)k dio: > > > Doesn't image.GetData () return RGB, and not RGBA, data? > > > > > > On 3/29/07, *altern* <al...@gm... <mailto:al...@gm...>> > > wrote: > > > > > > thanks andrew, i dont know how i did not find this myself, i was > > > looking in > > > wxBitmap class for this type of function. > > > still i dont get the images properly displayed. I can see it has > > similar > > > colors as the original but it is heavily pixelated. Is there any > > > difference in the format of the image data array itself between wx > > and > > > pygame? > > > > > > Andrew Wilson(e)k dio: > > > > Hello, > > > > You may want to try, > > > > > > > > bin = image.GetData() > > > > > > > > > > > > Thanks > > > > andrew > > > > > > > > > > > > > > > > On 3/29/07, *altern* < al...@gm... > > > <mailto:al...@gm...> <mailto: al...@gm... > > > <mailto:al...@gm...>>> wrote: > > > > > > > > hi > > > > > > > > I am trying to translate a pygame+opengl application to > > > wx+opengl. > > > > And I > > > > am stuck at the function to import images to create OpenGL > > > textures. > > > > > > > > I already asked for help on the wxpython list, but nobody > > > seemed to be > > > > interested on my problem, so i thought there might be some > > > wx-pyopengl > > > > users in the pyopengl list. > > > > > > > > This is the pygame code: > > > > > > > > surface = pygame.image.load(path) > > > > if surface.get_alpha is None: > > > > surface = surface.convert () > > > > else: > > > > surface = surface.convert_alpha () > > > > bin = pygame.image.tostring(surface, "RGBA", 1) > > > > w, h = surface.get_width(), surface.get_height() > > > > textid = glGenTextures(1) > > > > glBindTexture(GL_TEXTURE_2D, textid) > > > > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, > > > GL_UNSIGNED_BYTE, > > > > bin) > > > > ... and so on ... > > > > > > > > and this is the wx code i am using : > > > > > > > > image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) > > > > bin = image.ConvertToBitmap() > > > > w,h = image.GetWidth(), image.GetHeight() > > > > textid = glGenTextures(1) > > > > glBindTexture(GL_TEXTURE_2D, textid) > > > > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, > > > GL_UNSIGNED_BYTE, > > > > bin) > > > > ... etc ... > > > > > > > > It doesnt crash but the texture that OpenGL displays in not > > > at all the > > > > image i am importing but some weird random colors. I guess > > > this is the > > > > bit that i am missing, since printing > > > "image.ConvertToBitmap()" returns > > > > a wxBitmap instance and not the image data > > > > bin = pygame.image.tostring(surface, "RGBA", 1) > > > > > > > > I have been trying to find out how to access the data an > > > looking for > > > > examples on the net but did not find anything. > > > > > > > > any tips? thanks! > > > > > > > > enrike > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------- > > > > Take Surveys. Earn Cash. Influence the Future of IT > > > > Join SourceForge.net's Techsay panel and you'll get the > > > chance to > > > > share your > > > > opinions on IT & business topics through brief surveys-and > > > earn cash > > > > > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > > > < > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > > > > > > > > < > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > >> > > > > _______________________________________________ > > > > PyOpenGL Homepage > > > > http://pyopengl.sourceforge.net < > > http://pyopengl.sourceforge.net> > > > > _______________________________________________ > > > > PyOpenGL-Users mailing list > > > > PyO...@li... > > > <mailto: PyO...@li...> > > > > <mailto: PyO...@li... > > > <mailto: PyO...@li...>> > > > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------------------------- > > > Take Surveys. Earn Cash. Influence the Future of IT > > > Join SourceForge.net 's Techsay panel and you'll get the chance to > > > share your > > > opinions on IT & business topics through brief surveys-and earn > > cash > > > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > > > > _______________________________________________ > > > PyOpenGL Homepage > > > http://pyopengl.sourceforge.net > > > _______________________________________________ > > > PyOpenGL-Users mailing list > > > PyO...@li... > > > <mailto: PyO...@li...> > > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > > > ------------------------------------------------------------------------- > > > Take Surveys. Earn Cash. Influence the Future of IT > > > Join SourceForge.net's Techsay panel and you'll get the chance to > > share your > > > opinions on IT & business topics through brief surveys-and earn cash > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > > > > > > > > > > > ------------------------------------------------------------------------ > > > > > > _______________________________________________ > > > PyOpenGL Homepage > > > http://pyopengl.sourceforge.net > > > _______________________________________________ > > > PyOpenGL-Users mailing list > > > PyO...@li... > > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > > ------------------------------------------------------------------------- > > > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to share > > your > > opinions on IT & business topics through brief surveys-and earn cash > > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > _______________________________________________ > > PyOpenGL Homepage > > http://pyopengl.sourceforge.net > > _______________________________________________ > > PyOpenGL-Users mailing list > > PyO...@li... > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share > your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > |
From: Jason R. <ja...@il...> - 2007-03-29 18:45:00
|
yes PIL works great, this is how i've done it: def loadImage(imageName): from Image import open im = open(imageName) try: ix, iy = im.size[0], im.size[1] image = im.tostring("raw", "RGBA", 0, -1) except SystemError: ix, iy = im.size[0], im.size[1] image = im.tostring("raw", "RGBX", 0, -1) return ix, iy, image def createTexture(imageName): w, h, image = loadImage(imageName) id = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, id); glPixelStorei(GL_UNPACK_ALIGNMENT, 1) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image) return id Andrew Wilson wrote: > You may want to give PIL a shot. > http://www.pythonware.com/products/pil/ > Thanks > Andrew > > > > > > On 3/29/07, * Matthew Morris* <mj...@ms... > <mailto:mj...@ms...>> wrote: > > Maybe make a new buffer: RGB_RGB_RGB_..... and fill in the blanks > with the data from GetAlpha(). But there might be a better way, who > knows. > > -Matt > > > On 3/29/07, * altern* <al...@gm... <mailto:al...@gm...>> > wrote: > > you are right i just discovered that. I can see as well that > there is a > way to get the alpha info > image.GetAlpha() > but i am not sure how to use this two different types of data to > construct a valid opengl texture with alpha. > > Matthew Morris(e)k dio: >> Doesn't image.GetData () return RGB, and not RGBA, data? >> >> On 3/29/07, *altern* <al...@gm... > <mailto:al...@gm...> <mailto: al...@gm... > <mailto:al...@gm...>>> wrote: >> >> thanks andrew, i dont know how i did not find this myself, > i was >> looking in >> wxBitmap class for this type of function. >> still i dont get the images properly displayed. I can see > it has similar >> colors as the original but it is heavily pixelated. Is > there any >> difference in the format of the image data array itself > between wx and >> pygame? >> >> Andrew Wilson(e)k dio: >> > Hello, >> > You may want to try, >> > >> > bin = image.GetData() >> > >> > >> > Thanks >> > andrew >> > >> > >> > >> > On 3/29/07, *altern* < al...@gm... > <mailto:al...@gm...> >> <mailto: al...@gm... <mailto:al...@gm...>> > <mailto: al...@gm... <mailto:al...@gm...> >> <mailto: al...@gm... <mailto:al...@gm...>>>> wrote: >> > >> > hi >> > >> > I am trying to translate a pygame+opengl application to >> wx+opengl. >> > And I >> > am stuck at the function to import images to create > OpenGL >> textures. >> > >> > I already asked for help on the wxpython list, but > nobody >> seemed to be >> > interested on my problem, so i thought there might > be some >> wx-pyopengl >> > users in the pyopengl list. >> > >> > This is the pygame code: >> > >> > surface = pygame.image.load(path) >> > if surface.get_alpha is None: >> > surface = surface.convert () >> > else: >> > surface = surface.convert_alpha () >> > bin = pygame.image.tostring(surface, "RGBA", 1) >> > w, h = surface.get_width(), surface.get_height() >> > textid = glGenTextures(1) >> > glBindTexture(GL_TEXTURE_2D, textid) >> > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, >> GL_UNSIGNED_BYTE, >> > bin) >> > ... and so on ... >> > >> > and this is the wx code i am using : >> > >> > image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) >> > bin = image.ConvertToBitmap() >> > w,h = image.GetWidth(), image.GetHeight() >> > textid = glGenTextures(1) >> > glBindTexture(GL_TEXTURE_2D, textid) >> > gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, >> GL_UNSIGNED_BYTE, >> > bin) >> > ... etc ... >> > >> > It doesnt crash but the texture that OpenGL displays > in not >> at all the >> > image i am importing but some weird random colors. I > guess >> this is the >> > bit that i am missing, since printing >> "image.ConvertToBitmap()" returns >> > a wxBitmap instance and not the image data >> > bin = pygame.image.tostring(surface, "RGBA", 1) >> > >> > I have been trying to find out how to access the data an >> looking for >> > examples on the net but did not find anything. >> > >> > any tips? thanks! >> > >> > enrike >> > >> > >> > >> > ------------------------------------------------------------------------- > >> > Take Surveys. Earn Cash. Influence the Future of IT >> > Join SourceForge.net's Techsay panel and you'll get the >> chance to >> > share your >> > opinions on IT & business topics through brief > surveys-and >> earn cash >> > >> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> >> > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>> >> > >> > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> >> < > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>>> >> > _______________________________________________ >> > PyOpenGL Homepage >> > http://pyopengl.sourceforge.net < > http://pyopengl.sourceforge.net> >> > _______________________________________________ >> > PyOpenGL-Users mailing list >> > PyO...@li... > <mailto:PyO...@li...> >> <mailto: PyO...@li... > <mailto:PyO...@li...>> >> > <mailto: PyO...@li... > <mailto:PyO...@li...> >> <mailto: PyO...@li... > <mailto:PyO...@li...>>> >> > > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > <https://lists.sourceforge.net/lists/listinfo/pyopengl-users> >> > >> > >> >> >> >> > ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net 's Techsay panel and you'll get the > chance to >> share your >> opinions on IT & business topics through brief surveys-and > earn cash >> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> >> < > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>> >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... > <mailto:PyO...@li...> >> <mailto: PyO...@li... > <mailto:PyO...@li...>> >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users > <https://lists.sourceforge.net/lists/listinfo/pyopengl-users> >> >> >> >> > ------------------------------------------------------------------------ > >> >> > ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance > to share your >> opinions on IT & business topics through brief surveys-and > earn cash >> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> >> >> >> > ------------------------------------------------------------------------ >> >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... > <mailto:PyO...@li...> >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users > > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance > to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > <mailto:PyO...@li...> > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > <https://lists.sourceforge.net/lists/listinfo/pyopengl-users> > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > <mailto:PyO...@li...> > https://lists.sourceforge.net/lists/listinfo/pyopengl-users > <https://lists.sourceforge.net/lists/listinfo/pyopengl-users> > > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > ------------------------------------------------------------------------ > > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |
From: altern <al...@gm...> - 2007-03-29 17:41:06
|
ok, now i see that it is RGB and not RGBA format, so by doing GL_RGB instead of GL_RGBA i get the texture ok but with no alpha channel. gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGB, GL_UNSIGNED_BYTE, bin) altern(e)k dio: > thanks andrew, i dont know how i did not find this myself, i was looking in > wxBitmap class for this type of function. > still i dont get the images properly displayed. I can see it has similar > colors as the original but it is heavily pixelated. Is there any > difference in the format of the image data array itself between wx and > pygame? > > Andrew Wilson(e)k dio: >> Hello, >> You may want to try, >> >> bin = image.GetData() >> >> >> Thanks >> andrew >> >> >> >> On 3/29/07, *altern* < al...@gm... <mailto:al...@gm...>> >> wrote: >> >> hi >> >> I am trying to translate a pygame+opengl application to wx+opengl. >> And I >> am stuck at the function to import images to create OpenGL textures. >> >> I already asked for help on the wxpython list, but nobody seemed >> to be >> interested on my problem, so i thought there might be some >> wx-pyopengl >> users in the pyopengl list. >> >> This is the pygame code: >> >> surface = pygame.image.load(path) >> if surface.get_alpha is None: >> surface = surface.convert() >> else: >> surface = surface.convert_alpha () >> bin = pygame.image.tostring(surface, "RGBA", 1) >> w, h = surface.get_width(), surface.get_height() >> textid = glGenTextures(1) >> glBindTexture(GL_TEXTURE_2D, textid) >> gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, >> bin) >> ... and so on ... >> >> and this is the wx code i am using : >> >> image = wx.Image(path, wx.BITMAP_TYPE_ANY, -1) >> bin = image.ConvertToBitmap() >> w,h = image.GetWidth(), image.GetHeight() >> textid = glGenTextures(1) >> glBindTexture(GL_TEXTURE_2D, textid) >> gluBuild2DMipmaps(GL_TEXTURE_2D, 4, w, h, GL_RGBA, GL_UNSIGNED_BYTE, >> bin) >> ... etc ... >> >> It doesnt crash but the texture that OpenGL displays in not at all >> the >> image i am importing but some weird random colors. I guess this is >> the >> bit that i am missing, since printing "image.ConvertToBitmap()" >> returns >> a wxBitmap instance and not the image data >> bin = pygame.image.tostring(surface, "RGBA", 1) >> >> I have been trying to find out how to access the data an looking for >> examples on the net but did not find anything. >> >> any tips? thanks! >> >> enrike >> >> >> >> ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to >> share your >> opinions on IT & business topics through brief surveys-and earn cash >> >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> >> <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV> >> >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net <http://pyopengl.sourceforge.net> >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> <mailto:PyO...@li...> >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users >> >> > > > |