I'm guessing you are drawing it so small it's hardly 1 pixel. Ortho screen coordinates go from 0 to window's width etc. You are scaling the render by 0.025, try leave it out for ortho. Each character should be at least 6x10 in numeric coordinates.
I'm guessing you are drawing it so small it's hardly 1 pixel. Ortho screen coordinates go from 0 to window's width etc. You are scaling the render by 0.025, try leave it out for ortho. Each character should be at least 6x10 in numeric coordinates.
What do you mean?Originally Posted by User137
I tried leaving it out, but still no success.
[pascal]Vec3(-X, ...[/pascal]
X is always negative? This would draw it outside the screen.
By 6x10 i mean that it would be roughly the size of font on this forum page, in pixels. You just need to take into account that perspective view goes by default from ~ -2 to 2 when ortho is 0 to 800 or something, that is hundreds of times bigger number scale.
I use a negative X to draw the triangles in reverse order. Is that a bad idea?
It doesn't really work like that. If you want to render text at (300, 300), you'll end up with text being rendered at (-300, 300) which is out of the screen.Originally Posted by Brainer
If you want to reverse the triangles, you should alter the order of your vertices:
This is not tested. I hope you get what I mean.Code:Vertices.Add(V[0]); Vertices.Add(V[2]); Vertices.Add(V[1]); Vertices.Add(V[3]); Vertices.Add(V[2]); Vertices.Add(V[0]);
P.S: You are right about the fact that flipping an axis changes the rotation order. However, flipping X has some undesirable effects in this case.
Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.
Even if I use positive values on the X axis, the text is not rendered.Originally Posted by chronozphere
Hm, I've heard there's a need to map the text coordinates to the screen's coordinates before drawing in 2D mode. So it seems my current matrix calculations lead to no good, since there's a need to, I dunno how to call it, "project" the matrix onto a 2D plane? Maybe that's what should be done, what do you think?
Here's the quote:
if you were using a shader, you could just send vec2 with the screen size, then (vertex.x/(screen.x*0.5))-1 would scale the screen pixel to the correct place.. eg. (300/(600*0.5))-1 = 0 which would be the center of the screen.. in other words, you just need to send the vertex in screen coordinates and apply this scale instead of transforming it with the matrix in the shader.. it should work that way..
Can you do this first. Go in ortho mode and just draw a line from 50,50 to 100,50. If it is not showing then something is wrong with the setup. (GL_LINES)
Ok.
I tried it and the line is not shown in orthographic projection.
I figured it out!
I tried once again to turn the camera by 180 degrees and it worked. I had to change the matrix I used to create the final model-view matrix so that it could work. Here's how I do it.
Calculating the projection matrix
[code=delphi]
FProjMat := Mat4CreateOrtho(0, FWidth, 0, FHeight, -1.0, 1.0);
[/code]
Calculating the view matrix
[code=delphi]
CachedMatrix := Mat4Rotate(Mat4Identity(), Euler(0.0, 180.0, 0.0))
[/code]
Rendering the text
[code=delphi]
procedure TBrain2DText.RenderText(const Camera: TBrainCamera;
const AText: String; const ATextSize: Single; const AFont: TBrainFont);
var
CurX: Single;
Ch: Char;
Chaar, I, Ind: Integer;
ProjMat, ModelMat, ModelView: TBrainMatrix;
{ .: AddQuad :. }
procedure AddQuad(X, Y, Wid, Hgt, Tu, Tu2, Tv, Tv2: Single);
var
V: array [0 .. 3] of TBrainVector;
begin
TexCoords.Add(TexCoord(Tu, Tv));
TexCoords.Add(TexCoord(Tu2, Tv));
TexCoords.Add(TexCoord(Tu2, Tv2));
TexCoords.Add(TexCoord(Tu2, Tv2));
TexCoords.Add(TexCoord(Tu, Tv2));
TexCoords.Add(TexCoord(Tu, Tv));
V[0] := Vec3(-X, Y, 0.0);
V[1] := Vec3(-(X + Wid), Y, 0.0);
V[2] := Vec3(-(X + Wid), Y - Hgt, 0.0);
V[3] := Vec3(-X, Y - Hgt, 0.0);
Vertices.Add(V[0]);
Vertices.Add(V[1]);
Vertices.Add(V[2]);
Vertices.Add(V[2]);
Vertices.Add(V[3]);
Vertices.Add(V[0]);
end;
begin
// Before we begin, check if we have everything we need
if not Assigned(Camera) then
exit;
if not Assigned(Shader) then
exit;
if (AText = '') then
exit;
if not Assigned(AFont) then
exit;
if (ATextSize = 0.0) then
exit;
// If there are any leftovers from previous text, remove it
Vertices.Clear();
TexCoords.Clear();
// We are provided with parameters, so it's time to render
// the text
CurX := -Position.X;
if not (AFont.FontLoaded) then
exit;
// Iterate through the text
for I := 1 to Length(AText) do
begin
// Get the current character
Ch := AText[I];
Chaar := Integer(Ch);
// Check if the current character is a legal one
// (i.e. neither #10 nor #13). If it is, also check
// if it's not the Space character. If so, move the cursor
Ind := -1;
case Chaar of
32:
CurX := CurX + AFont.SpaceWidth * ATextSize;
10, 13: // No line-breaks supported
break;
else
Ind := AFont.CharacterLookup[Chaar];
end;
// If we have a valid character...
if (Ind > -1) then
begin
// Setup the cursor
CurX := CurX + AFont.CharacterInfo[Ind].A * ATextSize;
// Add a new quad which contains the character
AddQuad(CurX, Position.Y, AFont.CharacterInfo[Ind].Width * ATextSize,
AFont.CharacterInfo[Ind].Height * ATextSize, AFont.CharacterInfo[Ind].x1,
AFont.CharacterInfo[Ind].x2, AFont.CharacterInfo[Ind].y1,
AFont.CharacterInfo[Ind].y2);
// Move the cursor to the next character
CurX := CurX + AFont.CharacterInfo[Ind].C * ATextSize;
end;
end;
// Notify the object that its structure has changed
Self.StructureChanged();
// Enable blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Switch to the orthographic projection, enable the shader,
// and bind the texture
Camera.ProjectionType := ptOrthogonal2D;
Camera.ForceMatrixRecalc();
Shader.Enable();
AFont.FontTexture.Bind(0);
AFont.FontTexture.Apply();
// Calculate the matrices
ProjMat := Camera.ProjectionMatrix;
ModelMat := Mat4Translate(Mat4Identity(), Vec3(Position.X, Position.Y, 0.0));
ModelView := Mat4Multiply(ModelMat, Camera.Matrix);
// Update the shader
Shader.SetMatrix(ProjectionMatrixUniformName, @ProjMat);
Shader.SetMatrix(ModelViewMatrixUniformName, @ModelView);
// Finally, render the text using triangle strips
glBindVertexArray(GetVAO());
glDrawArrays(GL_TRIANGLE_STRIP, 0, Vertices.Count);
glBindVertexArray(0);
// Restore to defaults
Camera.ProjectionType := ptPerspective;
Camera.ForceMatrixRecalc();
glDisable(GL_BLEND);
end;
[/code]
Hope this helps.
*sigh* it was so much easier with display lists
When the moon hits your eye like a big pizza pie - that's an extinction level impact event.
Bookmarks