我正在为我的引擎实现文本渲染系统。这次我遇到了一个非常奇怪的问题:我有一个文本几何体包含生成的缓冲区,每次文本更改时我都会重新生成它们。要设置缓冲区,我使用glBufferData
并更新它 - glBufferSubData
。这完全有效,直到我想让我的缓冲区变大(至少包含一个char)。为此,我再次使用glBufferData
。我看到新的缓冲区正在到达目标GPU缓冲区,但我没有看到新的角色。多数民众赞成确切的问题。例如,我可以将新文本设置为new String(new char[2])
。这意味着我只能输入2个字符。
我可以在初始限制下查看和操纵所有字符,但不能超过上限。如果我将glBufferSubData
更改为glBufferData
则不会发生任何事情。我还试图破坏缓冲区,尝试创建新的指针......没有任何改变。
这是我的GLTracer日志:
[22.03.2015 13:39:38] [--------GAME_STARTED--------]
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_COLOR_ARRAY) -> false
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_TEXTURE_2D) -> false
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_TEXTURE_COORD_ARRAY) -> false
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_VERTEX_ARRAY) -> false
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_INDEX_ARRAY) -> false
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_NORMAL_ARRAY) -> false
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_NORMALIZE) -> false
[22.03.2015 13:39:43] [GLTrace] glGetInteger(GL_MATRIX_MODE) -> GL_MODELVIEW
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_DEPTH_TEST) -> false
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_ALPHA_TEST) -> false
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_STENCIL_TEST) -> false
[22.03.2015 13:39:43] [GLTrace] glGetInteger(GL_DEPTH_FUNC) -> GL_LESS
[22.03.2015 13:39:43] [GLTrace] glGetInteger(GL_CULL_FACE_MODE) -> GL_BACK
[22.03.2015 13:39:43] [GLTrace] glGetBoolean(GL_BLEND) -> false
[22.03.2015 13:39:43] [GLTrace] glGetInteger(GL_ARRAY_BUFFER_BINDING) -> 0
[22.03.2015 13:39:43] [GLTrace] glGetInteger(GL_ELEMENT_ARRAY_BUFFER_BINDING) -> 0
[22.03.2015 13:39:43] [GLTrace] glGetInteger(GL_TEXTURE_BINDING_2D) -> 0
[22.03.2015 13:39:43] [GLTrace] glEnableClientState(GL_VERTEX_ARRAY) -> DONE
[22.03.2015 13:39:43] [GLTrace] glEnableClientState(GL_INDEX_ARRAY) -> DONE
[22.03.2015 13:39:43] [GLTrace] glEnable(GL_DEPTH_TEST) -> DONE
[22.03.2015 13:39:43] [GLTrace] glDisable(GL_CULL_FACE) -> DONE
[22.03.2015 13:39:43] [GLTrace] glCullFace(Off) -> DONE
[22.03.2015 13:39:43] [GLTrace] glDepthFunc(LessOrEqual) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, -1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(ElementArray, -1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindTexture(Texture2D, -1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glViewport(0, 0, 800, 600) -> DONE
[22.03.2015 13:39:43] [GLTrace] glGetInteger(GL_MAX_TEXTURE_SIZE, java.nio.DirectIntBufferU[pos=0 lim=16 cap=16]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glGenTextures() -> 1
[22.03.2015 13:39:43] [GLTrace] glBindTexture(Texture2D, 1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glTexParameteri(Texture2D, GL_TEXTURE_BASE_LEVEL, 0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glTexParameteri(Texture2D, GL_TEXTURE_MAX_LEVEL, 0) -> DONE
[22.03.2015 13:39:43] [GLTrace] [Setting wrap mode: Clamp]
[22.03.2015 13:39:43] [GLTrace] glTexParameteri(Texture2D, GL_TEXTURE_WRAP_S, GL_CLAMP) -> DONE
[22.03.2015 13:39:43] [GLTrace] glTexParameteri(Texture2D, GL_TEXTURE_WRAP_T, GL_CLAMP) -> DONE
[22.03.2015 13:39:43] [GLTrace] -> DONE
[22.03.2015 13:39:43] [GLTrace] [Setting filter mode: Linear]
[22.03.2015 13:39:43] [GLTrace] glTexParameteri(Texture2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) -> DONE
[22.03.2015 13:39:43] [GLTrace] glTexParameteri(Texture2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR) -> DONE
[22.03.2015 13:39:43] [GLTrace] -> DONE
[22.03.2015 13:39:43] [GLTrace] [Setting texture environment mode: Modulate]
[22.03.2015 13:39:43] [GLTrace] glTexEnvi(Modulate)
[22.03.2015 13:39:43] [GLTrace] -> DONE
[22.03.2015 13:39:43] [GLTrace] glTexImage2D(Texture2D, 0, RGBA, 1024, 1024, 0, RGBA, UnsignedByte, java.nio.DirectByteBuffer[pos=0 lim=4194304 cap=4194304]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glGenBuffers() -> 1
[22.03.2015 13:39:43] [GLTrace] glGenBuffers() -> 2
[22.03.2015 13:39:43] [GLTrace] glGenBuffers() -> 3
[22.03.2015 13:39:43] [GLTrace] glGenBuffers() -> 4
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=24 cap=24], Dynamic) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(ElementArray, 2) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferData(ElementArray, java.nio.DirectIntBufferU[pos=0 lim=8 cap=8], Dynamic) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 3) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=16 cap=16], Dynamic) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 4) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=12 cap=12], Dynamic) -> DONE
[22.03.2015 13:39:43] [GLTrace] glGenBuffers() -> 5
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 5) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=32 cap=32], Static) -> DONE
[22.03.2015 13:39:43] [GLTrace] glClear(ColorAndDepth) -> DONE
[22.03.2015 13:39:43] [GLTrace] glLoadIdentity() -> DONE
[22.03.2015 13:39:43] [GLTrace] glMatrixMode(Projection) -> DONE
[22.03.2015 13:39:43] [GLTrace] glLoadIdentity() -> DONE
[22.03.2015 13:39:43] [GLTrace] gluPerspective(60.0, 1.3333334, 0.001, 5000.0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glMatrixMode(ModelView) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, -1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(ElementArray, -1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindTexture(Texture2D, -1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glLoadIdentity() -> DONE
[22.03.2015 13:39:43] [GLTrace] glMatrixMode(Projection) -> DONE
[22.03.2015 13:39:43] [GLTrace] glLoadIdentity() -> DONE
[22.03.2015 13:39:43] [GLTrace] gluOrtho2D(0.0, 800.0, 600.0, 0.0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glMatrixMode(ModelView) -> DONE
[22.03.2015 13:39:43] [GLTrace] glDisable(GL_DEPTH_TEST) -> DONE
[22.03.2015 13:39:43] [GLTrace] glPushMatrix() -> DONE
[22.03.2015 13:39:43] [GLTrace] glScalef(1.0, 1.0, 1.0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glTranslatef(0.0, 500.0, 1.0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glMultMatrix(java.nio.DirectFloatBufferU[pos=0 lim=16 cap=16]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glEnableClientState(GL_COLOR_ARRAY) -> DONE
[22.03.2015 13:39:43] [GLTrace] glEnable(GL_TEXTURE_2D) -> DONE
[22.03.2015 13:39:43] [GLTrace] glEnableClientState(GL_TEXTURE_COORD_ARRAY) -> DONE
[22.03.2015 13:39:43] [GLTrace] glEnableClientState(GL_NORMAL_ARRAY) -> DONE
[22.03.2015 13:39:43] [GLTrace] glEnable(GL_BLEND) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBlendFunc(Alpha) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindTexture(Texture2D, 1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 5) -> DONE
[22.03.2015 13:39:43] [GLTrace] glColorPointer(4, Float, 0, 0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glVertexPointer(3, Float, 0, 0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 4) -> DONE
[22.03.2015 13:39:43] [GLTrace] glNormalPointer(Float, 0, 0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 3) -> DONE
[22.03.2015 13:39:43] [GLTrace] glTexCoordPointer(2, Float, 0, 0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(ElementArray, 2) -> DONE
[22.03.2015 13:39:43] [GLTrace] glDrawElements(Quads, 8, UnsignedInt, 0) -> DONE
[22.03.2015 13:39:43] [GLTrace] glPopMatrix() -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferSubData(VertexArray, 0, java.nio.DirectFloatBufferU[pos=0 lim=12 cap=12]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferSubData(ElementArray, 0, java.nio.DirectIntBufferU[pos=0 lim=4 cap=4]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 3) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferSubData(VertexArray, 0, java.nio.DirectFloatBufferU[pos=0 lim=8 cap=8]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 4) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferSubData(VertexArray, 0, java.nio.DirectFloatBufferU[pos=0 lim=12 cap=12]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferSubData(VertexArray, 0, java.nio.DirectFloatBufferU[pos=0 lim=24 cap=24]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferSubData(ElementArray, 0, java.nio.DirectIntBufferU[pos=0 lim=8 cap=8]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 3) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferSubData(VertexArray, 0, java.nio.DirectFloatBufferU[pos=0 lim=16 cap=16]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 4) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferSubData(VertexArray, 0, java.nio.DirectFloatBufferU[pos=0 lim=12 cap=12]) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 1) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=36 cap=36], Dynamic) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferData(ElementArray, java.nio.DirectIntBufferU[pos=0 lim=12 cap=12], Dynamic) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 3) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=24 cap=24], Dynamic) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBindBuffer(VertexArray, 4) -> DONE
[22.03.2015 13:39:43] [GLTrace] glBufferData(VertexArray, java.nio.DirectFloatBufferU[pos=0 lim=12 cap=12], Dynamic) -> DONE
[22.03.2015 13:39:43] [---------GAME_ENDED---------]
提前致谢!
P.S。 Tracer仅保存第一帧渲染调用。然后它显示下一帧init调用。 glDraw
方法可以正常工作:顶点num更改。使用LWJGL 2.9.3。
BitmapText
public class BitmapText extends Text
{
protected int limit;
public BitmapText(float x, float y, String val, Font font)
{
super(val, font);
limit = val.toCharArray().length;
setController(ElementController.NULL);
geometry = new Geometry();
geometry.setLocation(x, y, 1f); // z?
geometry.setMesh(new Mesh()
{
{
renderMode = RenderingMode.Quads;
}
@Override
public void init()
{
initialized = true;
}
@Override
public void cleanup()
{
initialized = false;
}
});
updateMaterial();
setupMesh();
updateMesh();
}
@Override
public void setFont(Font font)
{
this.font = font;
updateMaterial();
}
@Override
public void setValue(String val)
{
this.value = val;
int tlimit = val.toCharArray().length;
if (limit < tlimit) {
limit = tlimit;
geometry.getMesh().cleanup();
}
updateMesh();
}
public int getLimit()
{
return limit;
}
public void updateMaterial()
{
if (geometry.getMaterial() == null) {
geometry.setMaterial(new Material());
geometry.getMaterial().setTransparent(true);
geometry.getMaterial().setBlendingMode(BlendingMode.Alpha);
}
geometry.getMaterial().setDiffuseMap(((BitmapFont) font).getTextureAtlas());
}
public void setupMesh()
{
VertexBuffer pb = (VertexBuffer) BufferManager.create(BufferType.Position, BufferUsage.Dynamic);
VertexBuffer ib = (VertexBuffer) BufferManager.create(BufferType.Index, BufferUsage.Dynamic);
VertexBuffer tb = (VertexBuffer) BufferManager.create(BufferType.TexCoord, BufferUsage.Dynamic);
VertexBuffer nb = (VertexBuffer) BufferManager.create(BufferType.Normal, BufferUsage.Dynamic);
Mesh m = geometry.getMesh();
m.getBuffers().put(pb.getType().ordinal(), pb);
m.getBuffers().put(ib.getType().ordinal(), ib);
m.getBuffers().put(tb.getType().ordinal(), tb);
m.getBuffers().put(nb.getType().ordinal(), nb);
}
public void updateMesh()
{
Mesh m = geometry.getMesh();
VertexBuffer pb = m.getBuffer(BufferType.Position);
VertexBuffer ib = m.getBuffer(BufferType.Index);
VertexBuffer tb = m.getBuffer(BufferType.TexCoord);
VertexBuffer nb = m.getBuffer(BufferType.Normal);
TextureAtlas atlas = (TextureAtlas) geometry.getMaterial().getDiffuseMap();
int[] idata = new int[value.length() * 4];
float[] pdata = new float[idata.length * m.getVertexSize()];
float[] tdata = new float[idata.length * m.getTexCoordSize()];
float[] ndata = Quad.baseNormal; // will not work! @todo rework normal generation
float cw = 64f;
float ch = 64f;
float k = 0.5f;
float ow = 24f;
for (int i = 0, iI = 0, pI = 0, tI = 0; i < value.length(); i++, iI += 4, pI += 12, tI += 8) {
int c = (int) value.charAt(i);
float tS = atlas.getCellSizeCoord();
float tSX = atlas.getCellXCoord(c);
float tSY = atlas.getCellYCoord(c);
float tEX = tSX + tS * k;
float tEY = tSY + tS;
float sX = i * ow;
float sY = 0;
float eX = i * ow + cw * k;
float eY = ch;
idata[iI] = iI;
idata[iI + 1] = iI + 1;
idata[iI + 2] = iI + 2;
idata[iI + 3] = iI + 3;
pdata[pI] = sX;
pdata[pI + 1] = sY;
pdata[pI + 2] = 0;
pdata[pI + 3] = eX;
pdata[pI + 4] = sY;
pdata[pI + 5] = 0;
pdata[pI + 6] = eX;
pdata[pI + 7] = eY;
pdata[pI + 8] = 0;
pdata[pI + 9] = sX;
pdata[pI + 10] = eY;
pdata[pI + 11] = 0;
tdata[tI] = tSX;
tdata[tI + 1] = tSY;
tdata[tI + 2] = tEX;
tdata[tI + 3] = tSY;
tdata[tI + 4] = tEX;
tdata[tI + 5] = tEY;
tdata[tI + 6] = tSX;
tdata[tI + 7] = tEY;
}
if (m.isInitialized()) {
BufferManager.update(pb, ClientBufferManager.createNIO(pdata));
BufferManager.update(ib, ClientBufferManager.createNIO(idata));
BufferManager.update(tb, ClientBufferManager.createNIO(tdata));
BufferManager.update(nb, ClientBufferManager.createNIO(ndata));
} else {
BufferManager.setup(pb, pdata, m.getVertexSize());
BufferManager.setup(ib, idata, m.getRenderMode().getSize());
BufferManager.setup(tb, tdata, m.getTexCoordSize());
BufferManager.setup(nb, ndata, m.getVertexSize());
m.init();
}
}
}
答案 0 :(得分:0)
这只是糟糕的程序结构的另一个例子。我没有更新在几何体中创建的颜色缓冲区。 如果你确定一切都没问题 - 关掉你能做的一切,然后再试一次。