text und clicks
-
hi leute
also ich kann erst seit ein paar tagen opengl...
ich will einen text auf den bildschirm ausgeben (ok das kann ich noch)...
somit hab ich nen 3d text und jetz will ich halt in diesem text einen zeilenumbrucht machen... mit \n geht das nich.... ich versteh es ned...
und wie kann ich z.b. nen klick auf den text catchen? so wie es z.b. ein internetbrowser bei links macht... halt wie ein menue...
waere sehr froh ueber eure hilfe
mfg
chubie
-
kommt drauf an wie du den text ausgibst
da gibts mehrere möglichkeiten
-
also den text gebe ich so aus
GLvoid BuildFont(GLvoid) // Build Our Bitmap Font { HFONT font; // Windows Font ID base = glGenLists(256); // Storage For 256 Characters font = CreateFont( 10, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch "Comic Sans MS"); // Font Name SelectObject(hDC, font); // Selects The Font We Created wglUseFontOutlines( hDC, // Select The Current DC 0, // Starting Character 255, // Number Of Display Lists To Build base, // Starting Display Lists 0.0f, // Deviation From The True Outlines 0.2f, // Font Thickness In The Z Direction WGL_FONT_POLYGONS, // Use Polygons, Not Lines gmf); // Address Of Buffer To Recieve Data } GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" Routine { float length=0; // Used To Find The Length Of The Text char text[256]; // Holds Our String va_list ap; // Pointer To List Of Arguments if (fmt == NULL) // If There's No Text return; // Do Nothing va_start(ap, fmt); // Parses The String For Variables vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers va_end(ap); for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length { length+=gmf[text[loop]].gmfCellIncX; // Increase Length By Each Characters Width } glTranslatef(-length/2,0.0f,0.0f); // Center Our Text On The Screen glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits glListBase(base); // Sets The Base Character to 0 glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text glPopAttrib(); // Pops The Display List Bits } int DrawGLScene(float col_r,float col_g,float col_b, int textbuffer, char text[]) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer glLoadIdentity(); // Reset The Current Modelview Matrix glTranslatef(0.0f,0.0f,-10.0f); // Move One Unit Into The Screen glColor3f(col_r,col_g,col_b); if(textbuffer == 0) glPrint("welcome to \n\r w3b internetbroswer", 0); return TRUE; // Everything Went OK return TRUE; // Everything Went OK }
code nach nehe tutorial...
is die ausgabe dazu faehig oder soll ich eine ander nehmen?
mfg
-
den code für die textverarbeitung musst du halt selber schreiben. oder du benutzt clanlib (www.clanlib.org).
wenn dus selber machst, muss du für jeden satz, höhe, breite, startposition, anzahl zeilen und buchstaben pro zeile speichern.
bei nem klick schaust du einfach ob die cursorposition grösser als die startposition des satzes und kleiner als dessen länge/höhe war.
zeilenumbrüche musst du auch selbst basteln.
ausgabe bis du auf \n triffst->dann ausgabeposition um fonthöhe auf der y-achse nach unten und x-achse zurück zur startpositiongruss sov