SDL_ttf and OpenGL

Just like the subject says, this is about using SDL_ttf with OpenGL.
Does anyone know how I can get the text to show up on screen with the 3d
environment?

Do I need to update the main video surface as well as call
SDL_GL_SwapBuffers()? If so, what order do I call them in?
I can get SDL_ttf to work on a 2D screen, but it doesn’t display
anything when OpenGL is enabled.

Kevin Fields
kevin at thedorvo.net

Just like the subject says, this is about using SDL_ttf with OpenGL.
Does anyone know how I can get the text to show up on screen with the 3d
environment?

Do I need to update the main video surface as well as call
SDL_GL_SwapBuffers()? If so, what order do I call them in?
I can get SDL_ttf to work on a 2D screen, but it doesn’t display
anything when OpenGL is enabled.

Kevin Fields
kevin at thedorvo.net

Kevin wrote:

Just like the subject says, this is about using SDL_ttf with OpenGL.
Does anyone know how I can get the text to show up on screen with the 3d
environment?

Do I need to update the main video surface as well as call
SDL_GL_SwapBuffers()? If so, what order do I call them in?
I can get SDL_ttf to work on a 2D screen, but it doesn’t display
anything when OpenGL is enabled.

Yes, unless you use the (deprecated evil) SDL_OPENGLBLIT that won’t work.

What you should do is use the surface returned by SDL_ttf to create an
OpenGL texture, and then draw a quad on-screen with that texture.
Btw, SDL blitting routines are very convenient to convert from one pixel
format to another, and thus can be used to painlessly convert your
surface to a format suitable for OpenGL texture creation.

Stephane

probably what you want to do is render the text to a surface, convert the
sdl surface to a gl texture and then use that texture.

for static text like “Score:” you could render it once and use it many
times, while dynamic text like the actual score of a player, youd have to
re-render whenever that number changed.> ----- Original Message -----

From: kevin@thedorvo.net (Kevin Fields)
To: “SDL Mailing List”
Sent: Wednesday, April 28, 2004 10:39 AM
Subject: [SDL] SDL_ttf and OpenGL

Just like the subject says, this is about using SDL_ttf with OpenGL.
Does anyone know how I can get the text to show up on screen with the 3d
environment?

Do I need to update the main video surface as well as call
SDL_GL_SwapBuffers()? If so, what order do I call them in?
I can get SDL_ttf to work on a 2D screen, but it doesn’t display
anything when OpenGL is enabled.

Kevin Fields
kevin at thedorvo.net


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Ok, so after I convert the SDL_Surface to a gl texture, before I draw
it, I’d have to switch to Ortho view, wouldn’t I?

Alan> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Wolfe
Sent: Wednesday, April 28, 2004 4:56 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL_ttf and OpenGL

probably what you want to do is render the text to a surface, convert
the
sdl surface to a gl texture and then use that texture.

for static text like “Score:” you could render it once and use it many
times, while dynamic text like the actual score of a player, youd have
to
re-render whenever that number changed.

----- Original Message -----
From: “Kevin”
To: “SDL Mailing List”
Sent: Wednesday, April 28, 2004 10:39 AM
Subject: [SDL] SDL_ttf and OpenGL

Just like the subject says, this is about using SDL_ttf with OpenGL.
Does anyone know how I can get the text to show up on screen with
the 3d

environment?

Do I need to update the main video surface as well as call
SDL_GL_SwapBuffers()? If so, what order do I call them in?
I can get SDL_ttf to work on a 2D screen, but it doesn’t display
anything when OpenGL is enabled.

Kevin Fields
kevin at thedorvo.net


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

up to you…gl is really flexible so it depends if thats what you want to do
or not

another way to do it would just be to draw a quad to the screen that was
paralel to the screen (maybe turning off depth testing for this).> ----- Original Message -----

From: kevin@thedorvo.net (Kevin Fields)
To:
Sent: Wednesday, April 28, 2004 1:25 PM
Subject: RE: [SDL] SDL_ttf and OpenGL

Ok, so after I convert the SDL_Surface to a gl texture, before I draw
it, I’d have to switch to Ortho view, wouldn’t I?

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Alan
Wolfe
Sent: Wednesday, April 28, 2004 4:56 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL_ttf and OpenGL

probably what you want to do is render the text to a surface, convert
the
sdl surface to a gl texture and then use that texture.

for static text like “Score:” you could render it once and use it many
times, while dynamic text like the actual score of a player, youd have
to
re-render whenever that number changed.

----- Original Message -----
From: “Kevin”
To: “SDL Mailing List”
Sent: Wednesday, April 28, 2004 10:39 AM
Subject: [SDL] SDL_ttf and OpenGL

Just like the subject says, this is about using SDL_ttf with OpenGL.
Does anyone know how I can get the text to show up on screen with
the 3d

environment?

Do I need to update the main video surface as well as call
SDL_GL_SwapBuffers()? If so, what order do I call them in?
I can get SDL_ttf to work on a 2D screen, but it doesn’t display
anything when OpenGL is enabled.

Kevin Fields
kevin at thedorvo.net


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Ok, another question on this, the following is the function that I use
to build my texture of strings and try to generate it. I seem to keep
getting a Segment Fault error when I run the program from this function
though.

void CFontManager::Update()
{
SDL_Surface *pScreen = 0;
SDL_Surface *pFinal = 0;

for (m_pit = m_PrintList.begin(); m_pit != m_PrintList.end();

++m_pit)
{
SDL_BlitSurface(m_pit->pSurface, 0, pFinal,
&(m_pit->pRect));
}
m_PrintList.clear();

glBindTexture(GL_TEXTURE_2D, m_uTextTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,

GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);

// this is where I’m getting the error
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pFinal->w, pFinal->h, 0,
GL_RGB, GL_UNSIGNED_BYTE, pFinal->pixels);

glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, m_uTextTexture);
glBegin(GL_QUADS);
	// top left
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-100.0f, 100.0f, -1.0f);
	// bottom left
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-100.0f, -100.0f, -1.0f);
	// bottom right
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(100.0f, -100.0f, -1.0f);
	// top right
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(100.0f, 100.0f, -1.0f);
glEnd();
glEnable(GL_DEPTH_TEST);
}

Alan> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Wolfe
Sent: Wednesday, April 28, 2004 5:45 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL_ttf and OpenGL

up to you…gl is really flexible so it depends if thats what you want
to
do
or not

another way to do it would just be to draw a quad to the screen that
was
paralel to the screen (maybe turning off depth testing for this).

----- Original Message -----
From: “Kevin”
To:
Sent: Wednesday, April 28, 2004 1:25 PM
Subject: RE: [SDL] SDL_ttf and OpenGL

Ok, so after I convert the SDL_Surface to a gl texture, before I
draw

it, I’d have to switch to Ortho view, wouldn’t I?

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf
Of

Alan

Wolfe
Sent: Wednesday, April 28, 2004 4:56 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL_ttf and OpenGL

probably what you want to do is render the text to a surface,
convert

the

sdl surface to a gl texture and then use that texture.

for static text like “Score:” you could render it once and use it
many

times, while dynamic text like the actual score of a player, youd
have

to

re-render whenever that number changed.

----- Original Message -----
From: “Kevin”
To: “SDL Mailing List”
Sent: Wednesday, April 28, 2004 10:39 AM
Subject: [SDL] SDL_ttf and OpenGL

Just like the subject says, this is about using SDL_ttf with
OpenGL.

Does anyone know how I can get the text to show up on screen
with

the 3d

environment?

Do I need to update the main video surface as well as call
SDL_GL_SwapBuffers()? If so, what order do I call them in?
I can get SDL_ttf to work on a 2D screen, but it doesn’t display
anything when OpenGL is enabled.

Kevin Fields
kevin at thedorvo.net


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I forgot to mention what m_PrintList consisted of.

vector m_PrintList;

and sPrintSurface is defined as:

struct sPrintSurface
{
SDL_Surface *pSurface;
SDL_Rect pRect;
}

In case that helps any.
What I’m doing in my Print() function is building the surface and rect
and adding them to an sPrintSurface structure, then doing a push_back()
on the m_PrintList.
I didn’t want to be generating the texture more than once a frame, so I
thought this way would work… apparently not. The SDL_Surface *pFinal
doesn’t even appear to be affected in my SDL_BlitSurface() call.

Kevin

Ok, another question on this, the following is the function that I use
to build my texture of strings and try to generate it. I seem to keep
getting a Segment Fault error when I run the program from this
function
though.

void CFontManager::Update()
{
SDL_Surface *pScreen = 0;
SDL_Surface *pFinal = 0;

for (m_pit = m_PrintList.begin(); m_pit != m_PrintList.end();
++m_pit)
{
SDL_BlitSurface(m_pit->pSurface, 0, pFinal,
&(m_pit->pRect));
}
m_PrintList.clear();

glBindTexture(GL_TEXTURE_2D, m_uTextTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);

// this is where I’m getting the error
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pFinal->w, pFinal->h, 0,
GL_RGB, GL_UNSIGNED_BYTE, pFinal->pixels);

glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, m_uTextTexture);
glBegin(GL_QUADS);
// top left
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-100.0f, 100.0f, -1.0f);
// bottom left
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-100.0f, -100.0f, -1.0f);
// bottom right
glTexCoord2f(1.0f, 1.0f);
glVertex3f(100.0f, -100.0f, -1.0f);
// top right
glTexCoord2f(1.0f, 0.0f);
glVertex3f(100.0f, 100.0f, -1.0f);
glEnd();
glEnable(GL_DEPTH_TEST);
}

Of> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Sent: Wednesday, April 28, 2004 6:23 PM
To: sdl at libsdl.org
Subject: RE: [SDL] SDL_ttf and OpenGL

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf
Alan
Wolfe
Sent: Wednesday, April 28, 2004 5:45 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL_ttf and OpenGL

up to you…gl is really flexible so it depends if thats what you
want
to

do
or not

another way to do it would just be to draw a quad to the screen that
was
paralel to the screen (maybe turning off depth testing for this).

----- Original Message -----
From: “Kevin”
To:
Sent: Wednesday, April 28, 2004 1:25 PM
Subject: RE: [SDL] SDL_ttf and OpenGL

Ok, so after I convert the SDL_Surface to a gl texture, before I
draw

it, I’d have to switch to Ortho view, wouldn’t I?

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On
Behalf
Of

Alan

Wolfe
Sent: Wednesday, April 28, 2004 4:56 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL_ttf and OpenGL

probably what you want to do is render the text to a surface,
convert

the

sdl surface to a gl texture and then use that texture.

for static text like “Score:” you could render it once and use
it
many

times, while dynamic text like the actual score of a player,
youd
have

to

re-render whenever that number changed.

----- Original Message -----
From: “Kevin”
To: “SDL Mailing List”
Sent: Wednesday, April 28, 2004 10:39 AM
Subject: [SDL] SDL_ttf and OpenGL

Just like the subject says, this is about using SDL_ttf with
OpenGL.

Does anyone know how I can get the text to show up on screen
with

the 3d

environment?

Do I need to update the main video surface as well as call
SDL_GL_SwapBuffers()? If so, what order do I call them in?
I can get SDL_ttf to work on a 2D screen, but it doesn’t
display

anything when OpenGL is enabled.

Kevin Fields
kevin at thedorvo.net


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Kevin wrote:

Ok, another question on this, the following is the function that I use
to build my texture of strings and try to generate it. I seem to keep
getting a Segment Fault error when I run the program from this function
though.

void CFontManager::Update()
{
SDL_Surface *pScreen = 0;
SDL_Surface *pFinal = 0;

Where is pFinal allocated ? You should allocate all src & dst surfaces
before blitting.
(hint : that’s the place you can allocate pFinal with a format suitable
for OpenGL textures, like RGB8/RGBA8, see the SDL_CreateRGBSurface doc)

Stephane

Still not working.
What I did was make the pFinal surface (and changed it to
m_pRenderSurface) a member of my font manager, and did the following in
the Init function for the manager:

Uint32 rmask, gmask, bmask, amask;

/* SDL interprets each pixel as a 32-bit number, so our masks must

depend
on the endianness (byte order) of the machine */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

m_pRenderSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 800, 600, 32,
rmask, gmask, bmask, amask);
if(m_pRenderSurface == 0)
{
printf(“CreateRGBSurface failed: %s\n”, SDL_GetError());
}

You had mentioned the SDL_OPENGLBLIT flag. How does that work?

Stephane Marchesin

Kevin wrote:

Ok, another question on this, the following is the function that I
use

to build my texture of strings and try to generate it. I seem to keep
getting a Segment Fault error when I run the program from this
function

though.

void CFontManager::Update()
{
SDL_Surface *pScreen = 0;
SDL_Surface *pFinal = 0;

Where is pFinal allocated ? You should allocate all src & dst surfaces
before blitting.
(hint : that’s the place you can allocate pFinal with a format
suitable
for OpenGL textures, like RGB8/RGBA8, see the SDL_CreateRGBSurface
doc)> -----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Sent: Wednesday, April 28, 2004 6:52 PM
To: sdl at libsdl.org
Subject: Re: [SDL] SDL_ttf and OpenGL

Stephane


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Kevin

Ok, another question on this, the following is the function that I use
to build my texture of strings and try to generate it. I seem to keep
getting a Segment Fault error when I run the program from this
function
though.

void CFontManager::Update()
{
SDL_Surface *pScreen = 0;
SDL_Surface *pFinal = 0;

for (m_pit = m_PrintList.begin(); m_pit != m_PrintList.end();
++m_pit)
{
SDL_BlitSurface(m_pit->pSurface, 0, pFinal,
&(m_pit->pRect));
}
m_PrintList.clear();

glBindTexture(GL_TEXTURE_2D, m_uTextTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST);

// this is where I’m getting the error
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, pFinal->w, pFinal->h, 0,
GL_RGB, GL_UNSIGNED_BYTE, pFinal->pixels);

When you do a BlitSurface, both surfaces must exist, SDL_BlitSurface does
not create the destination surface. This is why glTexImage2D is failing
because pFinal is still NULL (0). You should be checking the return value
of SDL_BlitSurface().

Use SDL_CreateRGBSurface() to create pFinal.

Also, learn to use asserts in your code to find out these things earlier on.

Regards,
Jeff>-----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Sent: Wednesday, April 28, 2004 6:23 PM
To: sdl at libsdl.org
Subject: RE: [SDL] SDL_ttf and OpenGL


Getting married? Find tips, tools and the latest trends at MSN Life Events.
http://lifeevents.msn.com/category.aspx?cid=married