Jump to content
  • Advertisement
Sign in to follow this  
crim

lersson #13 -SDL/Windows problem

This topic is 4709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My source uses OpenGL + SDL on windows, down the bottom of the lesson i couldn't find any sources for this combination and i am confused about an aspect of lesson 13 (printing text onto the screen). The example source I used is the DevC++ one. After many tries, i was not able to print text to the screen. I checked SDL and OpenGL for errors but none appeared. The source compiled correctly. The Z axis is set to -1. If someone knows the common problems assosiated with this, could you post them. One section i noted was this. hDC was used but SDL was never attached to it previously. oldfont = (HFONT)SelectObject(hDC, font); wglUseFontBitmaps(hDC, 32, 96, base); SelectObject(hDC, oldfont); DeleteObject(font); Futhermore SDL uses the command SDL_GL_SwapBuffers( ); but in the example this is used. SwapBuffers(hDC); hDC is not used at all with SDL. How do i overcome this problem?

Share this post


Link to post
Share on other sites
Advertisement
Ah sweet, thanks for that. Im to tired to look over it now, *bashes exams*, ill look at it in a few hours.

btw it was missing openal32.dll

Thanks

Share this post


Link to post
Share on other sites
SDL is supposed to be crossplatform don't know why they are labeled linux/SDL :)

As for matrix example, you need to have OpenAL installed

Share this post


Link to post
Share on other sites
Its labeled SDL/Linux because the interface is created with SDL hence is crossplatform but the way the font is implemented it is linux specific.

I think llvllatrix uses a bitmap and cuts the font from an image, which isnt how i intended to do it, i still have to wake up to read the source properly.

[Edited by - crim on June 21, 2005 3:16:51 PM]

Share this post


Link to post
Share on other sites
Quote:

I think llvllatrix uses a bitmap and cuts the font from an image, which isnt how i intended to do it, i still have to wake up to read the source properly.


I think bitmaped fonts are the closest you'll get to a cross platform friendly solution. If you're just using SDL on windows, then there may be a way but to be frank, its not worth the time and effort.

If what you need is 3d fonts, there should be ways to implement them using bitmap fonts. Sorry if my answers seem a bit general. I'm at school right now...otherwise I'd pull up some links...

Cheers,
- llvllatrix

Share this post


Link to post
Share on other sites
Im not really into bitmaps fonts, id rather use the OS method, to get it cross compadible im planning on doing it for windows and linux systems using #ifdef, etc. Double the amount of work but there is more control in the display of the fonts in the long run.

Further stuff i did to see if i can find the answer is, get a DC for the current interface using.

int sdl_interface::load_text ( string output_text ) {
HFONT loading_font;
base = glGenLists(96);
loading_font = CreateFont(
-24,
0,
0,
0,
FW_BOLD,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
FF_DONTCARE|DEFAULT_PITCH,
"Courier New");

if(loading_font == NULL)
cout << "CreateFont failed" << endl;

cout << "Win ERROR: " << GetLastError() << endl;

SDL_SysWMinfo wmi;
HWND current_hwnd;
SDL_VERSION( &wmi.version );
SDL_GetWMInfo( &wmi );
current_hwnd = wmi.window;
hDC = GetDC(current_hwnd);

cout << "Win ERROR: " << GetLastError() << endl;

if(hDC == NULL)
cout << "GetDC failed" << endl;

oldfont = (HFONT)SelectObject(hDC, loading_font); // Selects The Font We Want

if(oldfont == NULL)
cout << "oldfont failed" << endl;
if(oldfont == HGDI_ERROR)
cout << "oldfont HGDI_ERROR" << endl;

wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(hDC, oldfont); // Selects The Font We Want
DeleteObject(loading_font);

}
No errors came up on the above code.

Copy paste stuff between the lesson13 devc++ example and mine.

glTranslatef(0.0f,0.0f,-1.0f); // Move One Unit Into The Screen
// Pulsing Colors Based On Text Position
glColor3f(.5f,1.0f,.0f);
// Position The Text On The Screen
glRasterPos2f(-.5f, .0f);
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits ( NEW )
glListBase(base - 32); // Sets The Base Character to 32 ( NEW )

char text[256];
sprintf(text, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib();
cout << "ERROR:" << glGetError() << endl;
cout << "ERROR:" << SDL_GetError() << endl;

When i put that into the example it worked perfectly and printed aaaaaaaaaaa... on the screen.

Maybe its related to the display requirment, should it be on otha or prespective?

Which is...
int sdl_interface::interface_paste_flip() {

glClearColor( bg_colour.red, bg_colour.green, bg_colour.blue, 0 ); //background colour can be customize

glClearDepth(1.0f);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //destroy the world... i mean the buffer
glLoadIdentity();

/* TODO (#1#): make ortho objects dynamic */
glMatrixMode (GL_PROJECTION );
/* glPushMatrix();
glLoadIdentity();
glOrtho(-1.5, 1.5, -1.5*(GLfloat) display_data.width/(GLfloat) display_data.height, 1.5*(GLfloat) display_data.width/(GLfloat) display_data.height, -10, 10);
glPopMatrix();
*/

glLoadIdentity();

gluPerspective(45.0, (GLfloat) display_data.width/(GLfloat) display_data.height, 0.0, 60.0);

// glRotatef(270.0, 1.0, 0.0, 0.0);

glRotatef(cam_info.cam_rotation.x, 1.0, 0.0, 0.0);
glRotatef(cam_info.cam_rotation.y, 0.0, 1.0, 0.0);
glRotatef(cam_info.cam_rotation.z, 0.0, 0.0, 1.0);
glRotatef(turn, 1.0, 0.0, 1.0);
// turn = turn + 1.0;

// cout << "t " << cam_info.cam_translation.x << ":" << cam_info.cam_translation.y << ":" << cam_info.cam_translation.z << endl;
glTranslatef(cam_info.cam_translation.x, cam_info.cam_translation.y, cam_info.cam_translation.z);

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();



glTranslatef(0.0f,0.0f,-1.0f); // Move One Unit Into The Screen
// Pulsing Colors Based On Text Position
glColor3f(.5f,1.0f,.0f);
// Position The Text On The Screen
glRasterPos2f(-.5f, .0f);
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits ( NEW )
glListBase(base - 32); // Sets The Base Character to 32 ( NEW )

char text[256];
sprintf(text, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib();
cout << "ERROR:" << glGetError() << endl;
cout << "ERROR:" << SDL_GetError() << endl;

glLoadIdentity();

...... +400 lines

The init of sdl looks like this
int sdl_interface::interface_init( Uint32 flags ) {

int status = SDL_Init( flags ); //let sdl rip

if(status < 0)
{
cout << "Cannot init SDL, Error: (#" << status << ") " << SDL_GetError() << endl;
cout << "Forced to exit" << endl;
exit(1);
}

atexit(SDL_Quit); //force sdl to exit, as required by the standards for opengl, god save the ram

//just sets the opengl settings through sdl
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

glClearColor( 0, 0, 0, 0 ); //setting the backgroud to black, black is good

return 0;

}


with flags varible looking like 'SDL_OPENGL'
source is messy, shoot me :P

[Edited by - crim on June 23, 2005 1:06:28 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by crim
Im not really into bitmaps fonts, id rather use the OS method, to get it cross compadible im planning on doing it for windows and linux systems using #ifdef, etc. Double the amount of work but there is more control in the display of the fonts in the long run.


Take a look at SDL ttf. Depending on how much text you want to put on screen, you might be better of creating a font texture (for which you can use tis lib) or doing the platform specific stuff though.

PS: if you post such large chuncks of code please use [ source] tags instead of [ code] tags (without the space). As a bonus it does some fancy syntax highlighting.

Share this post


Link to post
Share on other sites
There was a reason why but now i cant remember it. Let me think on it. I just noticed i put lersson instead of lesson >_>

Share this post


Link to post
Share on other sites
I have a little tutorial on text input with OpenGL and SDL that uses NeHe's code from lesson 13 here. It should work fine as long as you are on a Win32 platform. if you want to use SDL_ttf with OpenGL, take a look at this post. Good luck!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!