wxGLString

If you have a cool piece of software to share, but you are not hosting it officially yet, please dump it in here. If you have code snippets that are useful, please donate!
Post Reply
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

wxGLString

Post by Auria » Tue Jan 06, 2009 9:43 pm

In my wxWidgets app, I use OpenGL and needed some string rendering. After playing with GLUT, QuesoGLC, GLTT, OGLFT, X, and a few more ( ;) ) without much success at getting it to work good and work everywhere, I though "hey, wxWidgets can do font rendering!". So here is the result : a simple set of classes to do font rendering on OpenGL! It's quite simple but should work for most simple needs ;)
================
wxGLString 0.1
================

wxGLString is a simple class allowing you to render text on a
OpenGL canvas with no additional dependency! It works best with
strings that don't change much. It also features number rendering -
those can change often without any performance hit. wxGLString
allows you to specify a font, font size, color, it can flip, rotate
and/or scale the text when rendering.

wxGLString was tested on wxMac 2.8.9 and wxGTK 2.8.9.

Installing wxGLString in your app is very simple : simply add wxGLString.cpp
to your project/makefile and #include "wxGLString.h".

wxGLString does not have any official documentation, however the
wxGLString.h header is heavily documented and can be used as a reference.
Furthermore, the sample included (sample.cpp) should get you started.

By Marianne Gagnon (aka Auria)
[email protected]
Here's an example of what it looks like when you use it :

Code: Select all


    wxGLString my_message;
    wxGLStringArray my_messages;
    wxGLNumberRenderer number;
    
    ...

    // init them the first time only
    if(first_time)
    {
        my_message = wxString( wxT("Hello world !!!") );
        my_message.setFont( wxFont( 50, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD) );
        my_message.consolidate(&dc);

        my_messages.addString( wxT("wxGLString can") );
        my_messages.addString( wxT("render strings in") );
        my_messages.addString( wxT("OpenGL easily!! ") );
        my_messages.addString( wxT("And with Unicode : \x1414 \x1562 \x1593") );
        my_messages.consolidate(&dc);

        number.consolidate(&dc);
    }


    // render string everytime
    my_message.bind();
    my_message.rotate(30);
    glColor3f(1,0,0);
    my_message.render(80,10);

    my_messages.bind();
    glColor3f(0,0.6,0);     my_messages.get(0).render(5,200);
    glColor3f(0,0,0.6);     my_messages.get(1).render(55,225);
    glColor3f(0,0.6,0.6);   my_messages.get(2).render(105,250);
    glColor3f(0.6,0.6,0);   my_messages.get(3).render(155,275);

    number.bind();
    glColor3f(0,0,0);
    number.renderNumber( -3.141591f, 250, 50 );

Released under wxWidgets license
Attachments
wxGLString.zip
(8.51 KiB) Downloaded 341 times
wxgtk_sshot.jpg
wxgtk_sshot.jpg (58.28 KiB) Viewed 8675 times
wxmac-sshot.jpg
wxmac-sshot.jpg (41.24 KiB) Viewed 8676 times
Last edited by Auria on Fri Jan 09, 2009 1:40 am, edited 1 time in total.

User avatar
T-Rex
Moderator
Moderator
Posts: 1195
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex » Wed Jan 07, 2009 2:49 pm

Looks nice but I have a question. Why visual output is looks different under Mac and Linux? Is it only because default font is different?

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Wed Jan 07, 2009 3:46 pm

T-Rex wrote:Looks nice but I have a question. Why visual output is looks different under Mac and Linux? Is it only because default font is different?
Exactly, that's simply because by default it uses the System's default font, which is quite different from system to system. You can specify a font, and then you should have much finer control.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Fri Jan 09, 2009 1:39 am

Here's version 0.2, contains many bugfixes and some efficiency improvements. :)
Attachments
wxGLString2.zip
(90.84 KiB) Downloaded 367 times

maninthewind
In need of some credit
In need of some credit
Posts: 6
Joined: Tue Nov 18, 2008 11:19 pm

Post by maninthewind » Thu Feb 05, 2009 10:21 am

nice ,it may be easy to put a mark on picture.

chertovmv
In need of some credit
In need of some credit
Posts: 2
Joined: Fri May 22, 2009 6:38 am

Post by chertovmv » Sat May 23, 2009 2:05 pm

Hi! It's work on Windows? I use VS2008 compiler.
I try build it, but i see only color box...

It's compiled when i comment this lines:
// my_messages.addString( wxT("And with Unicode : \x1414 \x1562 \x1593") );
// glColor3f(0.6,0.6,0); my_messages.get(3).render(155,275);

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria » Sat May 23, 2009 2:27 pm

chertovmv wrote:Hi! It's work on Windows? I use VS2008 compiler.
I try build it, but i see only color box...

It's compiled when i comment this lines:
// my_messages.addString( wxT("And with Unicode : \x1414 \x1562 \x1593") );
// glColor3f(0.6,0.6,0); my_messages.get(3).render(155,275);
Hi,

unfortunately I never tested under Windows :( About color box, you may need to see OpenGL calls

I'm not sure about why you commented out those line to get it to... compile? glColor3f should definitely not prevent compilation
"Keyboard not detected. Press F1 to continue"
-- Windows

chertovmv
In need of some credit
In need of some credit
Posts: 2
Joined: Fri May 22, 2009 6:38 am

Post by chertovmv » Sat May 23, 2009 10:18 pm

Sorry, my English is very bad(

Wrote a small project. It's work!
Visual Studio 2010, Windows 7

Image

I have error...

1) Replace "and" to "&&"

2) add double type because pow(double, double) and log(double).

Code: Select all

const int power_of_2_w = std::max(32, (int)pow( (double)2, (int)ceil((float)log((double)w)/log(2.0)) ));
const int power_of_2_h = std::max(32, (int)pow( (double)2, (int)ceil((float)log((double)h)/log(2.0)) ));
3) replace GL_CLAMP_TO_EDGE to GL_CLAMP because GL_CLAMP_TO_EDGE not found in glut.h

Code: Select all

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
4) when compile with

Code: Select all

my_messages.addString( wxT("And with Unicode : \x1414 \x1562 \x1593)) );
Compiler write in console errors:

Code: Select all

1>c:\dev\wxglstring test\src\renderpanel.cpp(90): error C2022: '5140' : too big for character
1>c:\dev\wxglstring test\src\renderpanel.cpp(90): error C2022: '5474' : too big for character
1>c:\dev\wxglstring test\src\renderpanel.cpp(90): error C2022: '5523' : too big for character
I don't know how write correctly unicode characters... (



VS2010 out in console when program exit:

Code: Select all

Detected memory leaks!
Dumping objects ->
{2263} normal block at 0x01893AB8, 4 bytes long.
 Data: <    > 03 00 00 00 
{2204} normal block at 0x01893C38, 4 bytes long.
 Data: <    > 02 00 00 00 
{2139} normal block at 0x01893E78, 4 bytes long.
 Data: <    > 01 00 00 00 
Object dump complete.
The program '[3188] wxGLString test.exe: Native' has exited with code 0 (0x0).
4 bytes in wxGLString my_message, 4 bytes in wxGLStringArray my_messages and 4 bytes in wxGLNumberRenderer number
i think that this memory leaks in:

Code: Select all

if(img != NULL) delete img;
img = new TextTexture(bmp);   // <- here
I commented code while i have memory leaks.
when commented "img = new TextTexture(bmp);" and code below this memory leak disappeared


wxGLString can draw russian characters without problem!

Auria, Thank you for you code!!! This is very convenient OpenGL Strings!)



Update! Add VS2008 Project
Attachments
wxGLString.rar
wxGLString VS2010 + VS2008 Project
(22.39 KiB) Downloaded 355 times

ssgrus
In need of some credit
In need of some credit
Posts: 1
Joined: Sat Mar 10, 2012 11:07 am

Re: wxGLString

Post by ssgrus » Sat Mar 10, 2012 11:12 am

Memory leak was in TextTexture.
Correct destructor is:

Code: Select all

TextTexture::~TextTexture()
{
    glDeleteTextures (1, ID);
    delete ID;
}

Post Reply