Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7761949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:15:59+00:00 2026-06-01T14:15:59+00:00

I am doing a big project and I want to show user the information

  • 0

I am doing a big project and I want to show user the information which looks nice.

All that I need it’s to be able to draw square and text inside.

I drew text and squares, but I cannot put them together. I even detected a place where problem is. It’s function SDL_SetVideoMode(mwidth,mheight,bpp,flags).

This place is highlighted. Thanks in advance!

using namespace std;
#define SPACING 0
TTF_Font *font=0;
int  font_size=16;
SDL_Surface *screen;)



void draw_text_at(SDL_Surface *scr,char *msg, int x0, int y0)
{
   int h;
   SDL_Rect r;

   SDL_Color fg={0,0,0,255};
   h=TTF_FontLineSkip(font);

    r.x=x0;
    r.y=y0-h;
    r.x=x0-TTF_GetFontOutline(font);
    r.y+=h+SPACING-TTF_GetFontOutline(font);

    SDL_Surface *surf=TTF_RenderText_Blended(font,msg,fg);

      if(surf)
      {   SDL_BlitSurface(surf,0,scr,&r);
          SDL_FreeSurface(surf);
      }
}

void window::handle_key_down(SDL_keysym * keysym)
{
  switch(keysym->sym)
  {
    case SDLK_ESCAPE:
     exit(0);
     break;

    default:
     break;
  }
}


 void window::setup_opengl()
 {
  float ratio=(float)mwidth/(float)mheight;
  glShadeModel(GL_SMOOTH);
  glCullFace(GL_BACK);
  glFrontFace(GL_CCW);

  glEnable(GL_CULL_FACE);
  glClearColor(1.0f,1.0f,1.0f,1.0f);
  glViewport(0,0,mwidth,mheight);

  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  gluPerspective(60.0,ratio,1.0,1024.0);
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
  glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
 }


 void window::draw_screen()
 {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();  // set  system of coordinates to the center of the screen
  glTranslatef(0.0,0.0,-10.0);
  glColor4f(0.0,1.0,1.0,1.0);

  glBegin(GL_QUADS);
   glVertex3f(-8, 0-2 ,0);
   glVertex3f(-2+-8,0-2 ,0);
   glVertex3f(-2+-8,-2-2,0);
   glVertex3f(0+-8, -2-2,0); 
  glEnd();

  glBegin(GL_QUADS);
   glVertex3f(-8+3, 0-2 ,0);
   glVertex3f(-2+-8+3,0-2 ,0);
   glVertex3f(-2+-8+3,-2-2,0);
   glVertex3f(0+-8+3, -2-2,0);
  glEnd ();

  SDL_GL_SwapBuffers( );
 }


void window(int quantity_of_disks, hard_disk &disk)
 {
   if((SDL_Init(SDL_INIT_VIDEO)<0))
    {printf("Could not initialize SDL: %s.\n", SDL_GetError());
    exit(-1); //return -1;
    }

   if(TTF_Init()==-1)
    {   printf("TTF_Init: %s\n", TTF_GetError());
        exit(-2);
    }

   const SDL_VideoInfo *info=NULL;
   int flags=0,bpp=0;
   info=SDL_GetVideoInfo();

   if(!info)
    {   fprintf(stderr,"Video query failed");
        SDL_Quit();
        exit(0);
    }

   bpp=info->vfmt->BitsPerPixel;

   SDL_GL_SetAttribute(SDL_GL_RED_SIZE,5);
   SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,5);
   SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,5);
   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);

HERE
IF I set flag to zero, I see text
If flag is set to SDL_OPENGL or SDL_OPENGLBLIT , I see squares

flas is transfered to function SDL_SetVideoMode
But I want see both. I tried change it, but..

  flags= 0;
 //   SDL_ANYFORMAT | SDL_OPENGLBLIT  | SDL_ASYNCBLIT

This moment is here:

     screen = SDL_SetVideoMode(mwidth,mheight,bpp,flags);

    if ( screen == NULL )
     { fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
      exit(-2); //return -2;
      }
     SDL_WM_SetCaption ("MBR informant",NULL);
     setup_opengl();

     glMatrixMode(GL_MODELVIEW);

    char *path_to_font="freefont-ttf/sfd/FreeMono.ttf";
   load_font(path_to_font, font_size);

   SDL_FillRect(screen,0,~0);

   while (1)
     {  draw_screen();
        char *msg="we typed it";
        draw_text_at(screen,msg,50,50);
        SDL_Flip(screen);

       SDL_Delay(1000);
       process_events ();
      }

     SDL_Quit();
     }

It looks like:

when variable flag = 0
when variable flag = 0

when variable flag = SDL_OPENGL
enter image description here

Due to big size of code I left only functions that have relation to painting.
Full file: http://rghost.net/37518422

SOLUTION

Thanks to jrok I ‘ve solved this problem so:
I defined rectangle.
SDL_Rect rect;
rect.x=0;
rect.y=0;
rect.w=150;
rect.h=140;

and I modified one part:

     while (1)
       {  draw_screen();
          char *msg="we typed it";
          draw_text_at(screen,msg,50,50);
          **SDL_FillRect (screen,&rect,100);**
          SDL_Flip(screen);
         SDL_Delay(1000);
        process_events ();
      }

and I got what I wanted:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:16:01+00:00Added an answer on June 1, 2026 at 2:16 pm

    You’re blitting the text with SDL_BlitSurface(). Exactly why it goes wrong I don’t know, but SDL wiki cleary says (SDL_BlitSurface):

    Like most surface manipulation functions in SDL, it should not be used together with OpenGL.

    If you wish to stick with OpenGL, this question covers some possibilities for rendering text:

    How to do OpenGL live text-rendering for a GUI?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a project which requires really big numbers, up to 100 digits. I
I am doing big project in Web Forms and entered a big mess of
I'm doing a project for my buddy and he is using big cartel. I
I want to use the boost library in a c++ project I'm doing in
I am working on a big project that involves a lot of web based
We're working on a big ASP.NET\VB.NET website project. I need to populate three dropdownlists.
I am currently doing a big project (by big I mean, many processes) where
In my project I need to upload a big file (~250GB) to remote server,
I've recently decided to take on a pretty big software engineering project that will
I am doing me university project and facing a big issue. i am developing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.