Bitmap ausserhalb Bildschirm zeichnen (Textscroll)



  • Hi Leute, ich hätte da gern mal ein kleines Problem. 🙂
    Ich habe gerade eben mit GLUT angefangen und möchte eine Bitmap von rechts nach links über den Bildschirm scrollen lassen. (Textscroll mit glutBitmapCharacter)
    Das Problem sieht folgendermassen aus: Immer wenn der linke Rand des Textes den linken Rand des Bildschirms berührt, verschwindet der komplette Text. (Der Text wird nicht langsam aus dem Bild gefahren, sondern verschwindet immer urplötzlich.)

    Soll:
    TestText
    estText
    stText
    tText
    ...

    Ist:
    TestText
    [nichts mehr]

    Ich hoffe ihr könnt mir helfen!
    Vielen Dank im Voraus!

    shadoweater

    #include <GL/glut.h>
    #include <iostream.h>
    #include <string.h>
    
    // globale Konstanten
    GLfloat const cLinkerRand = -100.0;
    GLfloat const cRechterRand = 100.0;
    
    // globale Variablen
    GLfloat x1 =0.0;
    GLfloat y1 =0.0;
    GLfloat rSize =25;
    
    GLfloat xStep =1.0;
    GLfloat yStep =1.0;
    
    GLfloat wndHeight;
    GLfloat wndWidth;
    
    GLint timerInterval = 10;
    
    GLint iTextbreite = 0;
    
    // Prototypen
    void renderScene(void);
    void timerFunction(int value);
    void setupRC(void);
    void changeSize(GLsizei w, GLsizei h);
    void drawText(void);
    
    //--- [ Funktionen ] ---
    void main()
    {
    	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    	glutCreateWindow("Scroll");
    	glutDisplayFunc(renderScene);
    	glutReshapeFunc(changeSize);
    	glutTimerFunc(timerInterval,timerFunction,1);
    	setupRC();
    
    	glutMainLoop();
    
    }
    
    void renderScene()
    {
    	glClear(GL_COLOR_BUFFER_BIT);
    	drawText();
    	glutSwapBuffers();
    
    }
    
    void timerFunction(int value)
    {
    	if (x1 < (cLinkerRand - iTextbreite))
    	{
    		x1 = cRechterRand - xStep ;
    	}
    	x1 -= xStep;
    
    	// Neuzeichnen und Timer auf 33ms setzen
    	glutPostRedisplay();
    	glutTimerFunc(timerInterval, timerFunction, 1);
    
    }
    
    void setupRC()
    {
    	glClearColor(0.0, 0.0, 0.0, 0.0);
    }
    
    void changeSize(GLsizei w, GLsizei h)
    {
    	GLfloat seitenverh;
    
    	if (h == 0)
    		h = 1;
    
    	glViewport(0, 0, w, h);
    
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    
    	seitenverh = GLfloat(w) / GLfloat(h);
    
    	if (w <= h)
    	{
    		wndWidth = cRechterRand;
    		wndHeight = cRechterRand / seitenverh;
    		glOrtho(cLinkerRand, cRechterRand, -wndHeight, wndHeight, 1.0, -1.0);
    	}
    	else
    	{
    		wndWidth = cRechterRand * seitenverh;
    		wndHeight = cRechterRand;
    		glOrtho(-wndWidth, wndWidth, cLinkerRand, cRechterRand, 1.0, -1.0);
    	}
    
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    
    }
    
    void drawText()
    {
    	glColor3f(1.0, 0.0, 0.0);
    	glRasterPos3f (x1, y1, 0);
    
    	iTextbreite =0;
    	char myText[] = "All Hail LST";
    
    	for (unsigned int i=0; i<= strlen(myText); i++)
    	{
    		glutBitmapCharacter (GLUT_BITMAP_TIMES_ROMAN_24, myText[i]);
    		iTextbreite += glutBitmapWidth(GLUT_BITMAP_TIMES_ROMAN_24, myText[i]);
    	}
    
    }
    


  • Kann OpenGL kein Clipping? Ich kenn die Funktionen nicht, also schau doch bitte nach.

    Bye, TGGC (Demo or Die)



  • Danke, hat sich erledigt.



  • ShadowEater schrieb:

    Danke, hat sich erledigt.

    Wie hat es sich erledigt? Ich hab nämlich das gleiche Problem und weiß keine Lösung.

    mfg.


Anmelden zum Antworten