PDA

View Full Version : SDL_TTF and Opengl transparency problem help please



emrekaya413
09-03-2017, 03:10 PM
hello i want to write text over 2d UI bar or little window like this :
https://i.hizliresim.com/lWJPgg.png (https://hizliresim.com/lWJPgg)


but my result was bad like this:
https://i.hizliresim.com/VMo8Jj.jpg (https://hizliresim.com/VMo8Jj)

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


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

Silence
09-04-2017, 12:29 AM
Use this (https://github.com/ocornut/imgui) for example.

emrekaya413
09-04-2017, 10:35 AM
Use this (https://github.com/ocornut/imgui) for example.

thanks for reply but it's too complicated for me

Silence
09-06-2017, 07:14 AM
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