tags:

views:

75

answers:

0

I had need on making PC emulator for developing monochrome LCD. After googling I found forum (can not remeber where) and sample code using GLUT. Current emulator look like this.

//mine .h source
#include "defines.h"
#include "displayemu.h"
TDisplayBuffer displaybuffer[SIZEOFDISPLAYX*SIZEOFDISPLAYY/8+1];


//usual hacks
#include <windows.h>
#define GLUTDISABLEATEXITHACK
#define GLUTNOWARNINGDISABLE
#define IGNOREPRAGMAWARRNINGSCUSTOM
#include <gl\gl.h>
#include <gl\glut.h>




//displaybuffer = displaybuffertmp;

//void displayemuinit(void);
void display(void);
void displayemuinit(void);

GLsizei wh = SIZEOFDISPLAYY ; // initial height of window
GLsizei ww = SIZEOFDISPLAYX ; // initial width of window


int displayemu(void)
{
    static init=0;
    glutInitDisplayMode(GLUTDOUBLE|GLUTRGB);
    glutInitWindowSize(SIZEOFDOT*SIZEOFDISPLAYX,SIZEOFDOT*SIZEOFDISPLAYY);
    glutInitWindowPosition(0,0);
    glutCreateWindow("Console Emulator 0.9.5");
    displayemuinit();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
}

void displayemuinit(void)
{

    glClearColor(1.0f ,1.0f ,1.0f ,1.0f);
    glColor3f(0.0f,0.0f,0.0f);
    glPointSize(SIZEOFDOT); // 10 pixel dot!
    glMatrixMode(GLPROJECTION);
    glLoadIdentity();
    gluOrtho2D ( 0.0, (GLdouble)ww, 0.0, (GLdouble)wh ); //Display area

}

void display(void)
{
    int i,j;
    TDisplayBuffer * pixelmatrix;
    pixelmatrix = displaybuffer;
    glClear(GLCOLORBUFFERBIT);
    glBegin(GLPOINTS);
    for (i=0;i<SIZEOFDISPLAYX;i++)
    {
        for (j=0;j<SIZEOFDISPLAYX;j++)
        {
            if((pixelmatrix[(i*SIZEOFDISPLAYX+j)>>3] & (1<<((i*SIZEOFDISPLAYX+j)& 7))) != 0 )
            {
               glVertex2i(i,SIZEOFDISPLAYY-j-1);
            }
        }
    }
    glutSwapBuffers();
}

this works well when called only once. Write bytes in single displaybuffer and call displayemu(). What I want is calling displayemu() when i finnished whit writing to displaymatrix, because this is aproach i am using on LCD device. What I found so far is that glutMainLoop() does not return. I am asking if i should use two treads and calling "SomeForceCallbackFunction()", some other library or something third. (i know that whit two treads i will have to add support for dubble buffering or locking, but that is not a problem)