Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: SDL_TTF and Opengl transparency problem help please

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    7

    SDL_TTF and Opengl transparency problem help please

    hello i want to write text over 2d UI bar or little window like this :



    but my result was bad like this:


    i am using gluOrtho2D for passing 2d from 3d and my code is as follows sorry for bad english how can i write like first picture with SDL_TTF ? help please

    Code cpp:
    glBindTexture(GL_TEXTURE_2D, texture);
     
        font=TTF_OpenFont("arial.ttf",32);
     
        SDL_Color color1={0,0,1};
     
        sFont=TTF_RenderUTF8_Blended(font,"nation1",color1);
     
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sFont->w, sFont->h, 0, GL_BGRA,GL_UNSIGNED_BYTE, sFont->pixels);
     
    enter2D();
     
    glEnable(GL_BLEND);
     
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
     
    glBegin(GL_QUADS);
     
    glTexCoord2f(0,0);
    glVertex2f(0.05,0.35);
    glTexCoord2f(1,0);
    glVertex2f(0.1,0.35);
    glTexCoord2f(1,1);
    glVertex2f(0.1,0.4);
    glTexCoord2f(0,1);
    glVertex2f(0.05,0.4);
     
    glEnd();
     
    glDisable(GL_BLEND);
     
    exit2D();
     
    enter2D();
     
    glEnable(GL_BLEND);
     
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
     
    glBindTexture(GL_TEXTURE_2D,Uresmi);
    glBegin(GL_QUADS);
     
    glTexCoord2f(1,0); 
    glVertex2f(0.2,0.3); 
    glTexCoord2f(0,0);
    glVertex2f(0,0.3); 
    glTexCoord2f(0,1); 
    glVertex2f(0,0.7); 
    glTexCoord2f(1,1); 
    glVertex2f(0.2,0.7); 
     
    glEnd();
     
     
    glDisable(GL_BLEND);
     
    exit2D();

    first gl_quads was text and second gl_quads was little window picture
    Last edited by Dark Photon; 09-03-2017 at 02:40 PM.

  2. #2
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    417
    Use this for example.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    7
    Quote Originally Posted by Silence View Post
    Use this for example.
    thanks for reply but it's too complicated for me

  4. #4
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    417
    Quote Originally Posted by emrekaya413 View Post
    thanks for reply but it's too complicated for me
    You have other alternatives which hopefully will be more easy to use:

    https://github.com/wjakob/nanogui
    http://www.fltk.org/index.php
    https://github.com/vurtun/nuklear

Tags for this Thread

Posting Permissions

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