Page 2 of 2 FirstFirst 12
Results 11 to 20 of 39

Thread: OpenGL GLSL - Text rendering query

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Quote Originally Posted by Chebmaster View Post
    You are wrong.
    I was not talking about "below 3.3". I was talking about "certain techniques below 2".
    Sure, let's pretend you didn't see the link I've posted, or let's pretend that Mark J. Kilgard, the principal engineer in Nvidia responsible of OpenGL driver development, is also wrong - you surely know better, don't you?

    Quote Originally Posted by Chebmaster View Post
    I performed benchmarking myself and I found that glBegin-style code begins to lag at about 20 000 vertices. That's how badly "left to rot" it is. That's how inefficiently it is emulated.
    I would like to see these benchmarks. On most desktop hardware we've done testing happens actually the opposite - glBegin/glEnd is close to performance to glDrawArrays with system pointers (similar to DrawPrimitiveUP in D3D9). When using OpenGL 4.5 features, including DSA, glMapNamedBufferRange (or glNamedBufferSubData) with immutable storage and GL_MAP_INVALIDATE_BUFFER_BIT, supplying vertex data for streaming each frame, it is difficult to get close to performance of the "legacy features" - in fact, we could only achieve better performance by using multiple buffers of gradually increasing sizes and other things like circular buffers with GL_MAP_PERSISTENT_BIT and otherwise AZDO-like features.

    So sure, this is very much legacy, but as long as it is supported and works, if you don't want to learn shaders or any third-party libraries, this is the quickiest way to render something in 3D. Pencil and paper are also very ancient and you can argue that with your new shiny iPad you never need to learn how to hand-write anymore, just until you drop the damn thing on a hard floor or your batteries run out...

  2. #2
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2
    And, in the end, I've just found out what I was doing wrong

    So this code works

    Code:
      glClearColor(0,0,0,1.0);
      glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
      glViewport(0,0,fRenderWidth,fRenderHeight);
      glLoadIdentity;
      gluOrtho2D(0,fRenderWidth,fRenderHeight,0);
      glEnable(GL_TEXTURE_2D);
      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      glBindTexture(GL_TEXTURE_2D,fCharacterSets[0].texture);
    
      for y:=0 to 15 do //5 do
      begin
        ty:=y*24;
        for x:=0 to 15 do //5 do
        begin
          tx:=x*24;
    
          idx:=x+(Y*16);
    
          glDisable(GL_BLEND);
    
          glBegin(GL_QUADS);
            glColor4f(fGLPaletteColors[0][idx,0],fGLPaletteColors[0][idx,1],fGLPaletteColors[0][idx,2],1.0);
            glVertex2i(tx,ty);
            glVertex2i(tx+16,ty);
            glVertex2i(tx+16,ty+16);
            glVertex2i(tx,ty+16);
          glEnd;
    
          // Render the font
          glColor4f(fGLPaletteColors[0][255-idx,0],fGLPaletteColors[0][255-idx,1],fGLPaletteColors[0][255-idx,2],1.0);
    
          glEnable(GL_BLEND);
    
          glBegin(GL_QUADS);
            glTexCoord2f(x*ONE_16TH,y*ONE_16TH);
            glVertex2i(tx,ty);
    
            glTexCoord2f(x*ONE_16TH+ONE_16TH,y*ONE_16TH);
            glVertex2i(tx+16,ty);
    
            glTexCoord2f(x*ONE_16TH+ONE_16TH,y*ONE_16TH+ONE_16TH);
            glVertex2i(tx+16,ty+16);
    
            glTexCoord2f(x*ONE_16TH,y*ONE_16TH+ONE_16TH);
            glVertex2i(tx,ty+16);
          glEnd;
    
        end;
      end;
    And this is the output....

    CorrectResults.PNG

    So what I was doing wrong, was binding the palette texture to the vertices of the background colour. Instead, this code simply uses glColor4f to set the colour, then creates a quad, specifies the points for the background. Turns on blending, changes the colour and creates a quad, specifying texture coordinates corresponding to the required character.

    Interestingly though, I had a problem that was really odd involving the second column (from the left) and the bottom row, being darker. No matter what I tried I couldn't stop this and it was like this was something to do with one of the textures. Originally I was loading my textures and setting these:-

    Code:
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    With those commented out, that problem went away.

    And that, as they say is that... now I can crack on and write some bad code to get something working.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  3. #3
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2
    Forgot to add... thanks for all the suggestions chaps
    :: AthenaOfDelphi :: My Blog :: My Software ::

  4. #4
    I'm glad you got it working, and welcome back to coding

    cheers,
    Paul

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •