BrowserBox with color ?

Talk about anything, including games and servers not affiliated with The Mana World.
Post Reply
Grz-
Peon
Peon
Posts: 8
Joined: 10 Nov 2006, 05:51

BrowserBox with color ?

Post by Grz- »

Hi,

I have problem with BrowerBox and color, i use this nice class for a guichan tutorial for my forum (and with only guichan not possibly have different color in a box) and in my simply example (with opengl) i not have different text color... look here ->

Image

And the code :

Code: Select all

#include <SDL>
#include <GL>
#include <GL>
#include <guichan>
#include <guichan>
#include <guichan>
#include <guichan>
 
#include "browserbox.h"

BrowserBox* mBrowserBox;
gcn::ScrollArea *ScrollArea;
gcn::Container* screen;
gcn::Container* cWin;
gcn::ImageFont* font;
gcn::Color* color;
gcn::SDLInput* input;
gcn::OpenGLGraphics* graphics;
gcn::OpenGLSDLImageLoader* img;
gcn::Gui* gui;
gcn::Window *windowUp;

void setup_gui(int w, int h)
{
   img = new gcn::OpenGLSDLImageLoader();
   gcn::Image::setImageLoader(img); 
   
   graphics = new gcn::OpenGLGraphics();
   graphics->setTargetPlane(w, h);
   
   input = new gcn::SDLInput();
   color = new gcn::Color::Color();
   
   screen = new gcn::Container();    
   screen->setDimension(gcn::Rectangle(0, 0, w, h));
   screen->setBaseColor(gcn::Color::Color(0,0,0,0));
   
   gui = new gcn::Gui();
   gui->setGraphics(graphics);
   gui->setInput(input); 
   gui->setTop(screen);
   
   font = new gcn::ImageFont("font.png", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\"");
   gcn::Widget::setGlobalFont(font);
   
   cWin = new gcn::Container();   
   cWin->setBaseColor(gcn::Color::Color(0,75,60,180));
   cWin->setOpaque(false);
   windowUp = new gcn::Window("Tutoriel");
   windowUp->setBaseColor(gcn::Color::Color(0,75,60,180));
   windowUp->setPadding(10);
   windowUp->setTitleBarHeight(20);
   windowUp->setAlignment(gcn::Graphics::CENTER);
   windowUp->add(cWin);
   cWin->setSize(400, 300);
   windowUp->resizeToContent();
   windowUp->setVisible(true);
  
   mBrowserBox = new BrowserBox();
   mBrowserBox->setOpaque(false);

   ScrollArea = new gcn::ScrollArea(mBrowserBox);
   ScrollArea->setDimension(gcn::Rectangle(5, 5, 388,288));

   cWin->add(ScrollArea);
  
   screen->add(windowUp, (w/2)-400/2, (h/2)-300/2);
   
   mBrowserBox->addRow("##3 Un test, rien de plus. :P");
   mBrowserBox->addRow("##5 ReTest");
}

void quit(int code)
{
   delete mBrowserBox;
   delete ScrollArea;
   delete screen;
   delete cWin;
   delete font;
   delete color;
   delete graphics;
   delete input;
   delete img;
   delete windowUp;
   delete gui;
   
   SDL_Quit();
   exit(code);
}

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

void process_events(void)
{
   SDL_Event event;

   while(SDL_PollEvent(&event))
   {
       switch(event.type) 
       {
           case SDL_KEYDOWN:
               handle_key_down(&event.key.keysym); break;
           case SDL_QUIT:
               quit(0); break;
       }
     input->pushInput(event);
   }
}

void draw_screen(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   gui->logic();
   gui->draw();

   SDL_GL_SwapBuffers();
}

void setup_opengl( int width, int height )
{
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();

   glOrtho(0,width,height,0,-1,1); 
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

}

int main(int argc, char *argv[])
{
   const SDL_VideoInfo* info = NULL;
   int width = 640;
   int height = 480;
   int bpp = 32;
   int flags = 0;

   if(SDL_Init(SDL_INIT_VIDEO) < 0)
   {
       printf("Video initialization failed: %s\n", SDL_GetError()); // initialisation echoue
       quit(1);
   }
   info = SDL_GetVideoInfo();
   if(!info)
   {
       printf("Video query failed: %s\n", SDL_GetError());
       quit(1);
   }

   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

   flags = SDL_OPENGL;

   if(SDL_SetVideoMode(width, height, bpp, flags) == 0 )
   {
       printf("Video mode set failed: %s\n", SDL_GetError());
       quit(1);
   }
   setup_opengl(width, height);

   setup_gui(width, height);
   
   while(1)    
   {
       process_events();
       draw_screen();
   }
   return 0;
}
(Sorry for my bad english, i'm french ;))

@++
Grz-
Peon
Peon
Posts: 8
Joined: 10 Nov 2006, 05:51

Post by Grz- »

I think my problem is in my implementation of browserbox... but i don't see the problem... :)

(Ps : Please delete the other post)
Grz-
Peon
Peon
Posts: 8
Joined: 10 Nov 2006, 05:51

Post by Grz- »

Hello, i still did not find the problem and i would like to know why that does not function, this blocking prevents me from continuing my tutoriel.

Bye.
User avatar
Bjørn
Manasource
Manasource
Posts: 1470
Joined: 09 Dec 2004, 18:50
Location: North Rhine-Westphalia, Germany
Contact:

Post by Bjørn »

Might it be that you're using a black font instead of a white one? For OpenGL to be able to color the texture to the font color, it needs to be white since whatever you blend black to, it stays black.
Grz-
Peon
Peon
Posts: 8
Joined: 10 Nov 2006, 05:51

Post by Grz- »

Thank's it is the problem... ;)
Grz-
Peon
Peon
Posts: 8
Joined: 10 Nov 2006, 05:51

Post by Grz- »

Hmm it there with still a problem, with defaut browser box font in TMW, test does not display correctly, it's transparency problem ?

Image

The code is the same one as that higher, i have just change font.
Than'ks for you'r help.
User avatar
Bjørn
Manasource
Manasource
Posts: 1470
Joined: 09 Dec 2004, 18:50
Location: North Rhine-Westphalia, Germany
Contact:

Post by Bjørn »

I can't see anything in your textbox, are you using the white font? To make your font visible, draw it in black. Example:

glColor3f(0.0, 0.0, 0.0);

Or if you're using gcn::Graphics, set the color to gcn::Color(0,0,0).

Hope that helps.
User avatar
yosuhara
Knight
Knight
Posts: 583
Joined: 16 Mar 2006, 21:19
Location: Slovakia
Contact:

Post by yosuhara »

Bjørn wrote:I can't see anything in your textbox, are you using the white font? To make your font visible, draw it in black. Example:

glColor3f(0.0, 0.0, 0.0);

Or if you're using gcn::Graphics, set the color to gcn::Color(0,0,0).

Hope that helps.
but there are letters though they are hard to see because of the yellow font
Image
Image
Image
User avatar
Bjørn
Manasource
Manasource
Posts: 1470
Joined: 09 Dec 2004, 18:50
Location: North Rhine-Westphalia, Germany
Contact:

Post by Bjørn »

yosuhara wrote:but there are letters though they are hard to see because of the yellow font
Ah, couldn't see that at all on the TFT at work, but yeah now I see them too. Still, the solution should be changing the color to black. :-)
Grz-
Peon
Peon
Posts: 8
Joined: 10 Nov 2006, 05:51

Post by Grz- »

I think that it is not its because in browserbox class the color is already set in black.

Code: Select all

    gcn::ImageFont *font = dynamic_cast<gcn>(getFont());

    graphics->setColor(BLACK);
I checked and it's similar.
The font used is defaut The Mana World browserbox font :

Image
Grz-
Peon
Peon
Posts: 8
Joined: 10 Nov 2006, 05:51

Post by Grz- »

Hi,

I tested and returned the code with "glColor3f" and "gcn::Color" but doesnt work... i have always the text in yellow and i don't understand why.

You have other idea ?
User avatar
Bjørn
Manasource
Manasource
Posts: 1470
Joined: 09 Dec 2004, 18:50
Location: North Rhine-Westphalia, Germany
Contact:

Post by Bjørn »

Nope, sorry.
Grz-
Peon
Peon
Posts: 8
Joined: 10 Nov 2006, 05:51

Post by Grz- »

Okay i'm gonna try looking into the code to see where the problem is, what is strange is that glcolor3f changes everything onscreen in opengl EXCEPT the font, i think its the font that is not converted

EDIT : but if i put a invalid character (for example tabulation character via fopen) on textbox the invalid character is a rectangle and this rectangle have color defined by ##color but the valid character, no. it's very strange...
-- IG -> Garzul- -> lvl 14 :) --
Post Reply