-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
1.92 TexData breaking changes not found #8764
Copy link
Copy link
Closed
Labels
Description
My Issue/Question:
Previously atlas had TexWidth, TexHeight, TexPixelsRGBA32, TexID
There is no mention in CHANGELOG which could aid in 1.91 to 1.92 transition
my guesses:
atlas.TexWidth -> atlas.TexData.Width
atlas.TexHeight -> atlas.TexData.Height
atlas.TexPixelsRGBA32 -> atlas.TexData.Pixels
atlas.TexID -> atlas.TexData:GetTexRef() for Image
Works mostly but I am failing to get glfw or sdl cursors from the font. It was previously done as seen in GetCursors
function gui.FontIcons(GL,source,ranges,size)
local path = require"anima.path"
local fontpath = path.chain(path.animapath(),"fonts","fontawesome-webfont.ttf")
source = source or fontpath
--ranges = ranges or ffi.new("ImWchar[3]",{0xf000,0xf2e0,0})
ranges = ranges or ffi.new("ImWchar[3]",{0xf000,0xf1fb,0})
size = size or 16
local FAicons = {source=source,size=size,ranges=ranges}
function FAicons:LoadFont()
FAicons.atlas = ig.GetIO().Fonts
local fnt_cfg = ig.ImFontConfig()
fnt_cfg.PixelSnapH = true
fnt_cfg.OversampleH = 1
FAicons.font = FAicons.atlas:AddFontFromFileTTF(source, size, fnt_cfg,ranges)
assert(FAicons.font~=nil,"could not load font!!!")
--self.font:SetFallbackChar(self.ranges[0])
end
function FAicons:Button(cp,ID)
--local glyph = self.font:FindGlyphNoFallback(cp + self.ranges[0])
--if glyph==nil then print("bad codepoint",cp);return false end
local glyph = self.font:FindGlyph(cp + self.ranges[0])
ID = ID or tostring(cp)
local ret = ig.ImageButton(ID,self.atlas.TexID, ig.ImVec2(self.size,self.size), ig.ImVec2(glyph.U0,glyph.V0), ig.ImVec2(glyph.U1,glyph.V1), ig.ImVec4(0,0,0,0), ig.ImVec4(1,1,1,1));
return ret
end
function FAicons:GetCursors(cps)
cps = cps or {hand=166,glass=2,glass_p=14,glass_m=16,pickcolor=0x01FB}--0x01FB}
self.cursorcps = cps
-- local img = ffi.new("unsigned char[?]",self.atlas.TexWidth * self.atlas.TexHeight * 4)
-- gl.glBindTexture(glc.GL_TEXTURE_2D,ffi.cast("GLuint",self.atlas.TexID))
-- gl.glGetTexImage(glc.GL_TEXTURE_2D,0,glc.GL_RGBA,glc.GL_UNSIGNED_BYTE,img);
print("atlas data",FAicons.atlas.TexWidth,FAicons.atlas.TexHeight)
--local imgp = ffi.new("unsigned char*[1]")
local wi = ffi.new("int[1]")
local hi = ffi.new("int[1]")
--self.atlas:GetTexDataAsRGBA32(imgp,wi,hi)
local atlas = ig.GetIO().Fonts
local img = ffi.cast("unsigned char*",atlas.TexPixelsRGBA32)
--print("wi,hi",wi[0],hi[0])
--local img = imgp[0]
local cursors = {}
for k,cp in pairs(cps) do
local glyph = self.font:FindGlyphNoFallback(cp + self.ranges[0])
assert(glyph~=nil,"no glyph!! "..(cp + self.ranges[0]))
local basex = math.floor(glyph.U0*self.atlas.TexWidth)
local basey = math.floor(glyph.V0*self.atlas.TexHeight)
local width = math.floor((glyph.U1-glyph.U0)*self.atlas.TexWidth)
local height = math.floor((glyph.V1-glyph.V0)*self.atlas.TexHeight)
print("glyph data",width,height,self.atlas.TexWidth,self.atlas.TexHeight)
if not GL.SDL then --glfw
local image = ffi.new("GLFWimage")
image.width = width
image.height = height
image.pixels = ffi.new("unsigned char[?]",width*height*4)
--
for i=0,width-1 do
for j = 0,height-1 do
for p=0,3 do
image.pixels[(i + j*width)*4 + p] = img[(basex+i + (basey+j)*self.atlas.TexWidth)*4 + p]
end
end
end
cursors[k] = glfw.glfwCreateCursor(image, 0, 0);
assert(cursors[k]~=nil,"glfwCreateCursor failed")
else --SDL
--local surface = sdl.createRGBSurface(0, width, height, 32, 0, 0, 0, 0);
local surface = sdl.C.SDL_CreateRGBSurfaceWithFormat(0, width, height, 32, sdl.PIXELFORMAT_ABGR8888)
local pitch = surface.pitch
--local formato = surface.format
local pixels = ffi.cast("unsigned char*",surface.pixels)
print("surface.pixels",pixels,pitch)
-- print(formato.format,sdl.PIXELFORMAT_RGBA8888,formato.palette, formato.BitsPerPixel, formato.BytesPerPixel)
-- for k,v in pairs(sdl) do
-- if formato.format == v then print("format",k); break end
-- end
for i=0,width-1 do
for j = 0,height-1 do
for p=0,3 do
--pixels[(i + j*width)*4 + p] = img[(basex+i + (basey+j)*self.atlas.TexWidth)*4 + p]
pixels[i*4 + j*pitch + p] = img[(basex+i + (basey+j)*self.atlas.TexWidth)*4 + p]
end
end
end
cursors[k] = sdl.createColorCursor(surface,0,0)
sdl.freeSurface(surface)
assert(cursors[k]~=nil,"sdl.createColorCursor failed")
end
end
return cursors
end
return FAicons
end --FAiconsReactions are currently unavailable