Local systems / textures

I use LabWindows with a I/O card to collect the data, the output from the gyroscope are in volts then i scale the volts to Deg/s and then i make euler calculation that will get rid of the gimbal effect. What i have now is the euler angles and I want to connect them to my cube that i have drawn in openGL.

Do I use the rotate command correct for a local coordinate system? Maybe i somehow clears the matrix so that when the next angle update try to rotate the cube it have forgotten the last position of the cube coordinate system.

At the same time i can ask about textures. I want to paint my cube with a bmp image and it works with the code i write. The trouble is that everytime the cube is updated i load the texture. This of course lead to memory leackage and and reduced performace in terms of sample time. I guess i can do this smarter and only load the texture once, maybe in the init function. But when i do this the texture will mot be visible. So i guess i somewhere clears that memory aswell. Any suggestions how to fix this?

This is some of my code:

void InitOGLControl(void)
{

// Puts the position of the cube in the LabWindows window
OGLSetCtrlAttribute (panelHandle, OGLControlPanel, OGLATTR_PROJECTION_TYPE, OGLVAL_PERSPECTIVE);
OGLSetCtrlAttribute (panelHandle, OGLControlPanel, OGLATTR_VIEW_DIRECTION, OGLVAL_USER_DEFINED);
OGLSetCtrlAttribute (panelHandle, OGLControlPanel, OGLATTR_VIEW_LATITUDE, DFLT_VIEW_LATITUDE);
OGLSetCtrlAttribute (panelHandle, OGLControlPanel, OGLATTR_VIEW_LONGITUDE, DFLT_VIEW_LONGITUDE);
OGLSetCtrlAttribute (panelHandle, OGLControlPanel, OGLATTR_VIEW_CENTERX,DFLT_VIEWPOINT_X);
OGLSetCtrlAttribute (panelHandle, OGLControlPanel, OGLATTR_VIEW_CENTERY,DFLT_VIEWPOINT_Y);
OGLSetCtrlAttribute (panelHandle, OGLControlPanel, OGLATTR_VIEW_CENTERZ,DFLT_VIEWPOINT_Z);
OGLSetCtrlAttribute (panelHandle, OGLControlPanel, OGLATTR_VIEW_DISTANCE,DFLT_VIEW_DISTANCE);

}

void RenderCubeImage(int fastFlag)
{

glPushAttrib(GL_ALL_ATTRIB_BITS);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_TEXTURE_2D); // Enable texture mapping ( NEW )
glShadeModel(GL_SMOOTH); // Enable smooth shading
glClearDepth(1.0f); // Depth buffer setup
glEnable(GL_DEPTH_TEST); // Enables depth testing
glDepthFunc(GL_LEQUAL); // The type of depth testing to do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really nice perspective calculations

// LoadGLTextures();

glRotatef(Xrotation,1.0f,0.0f,0.0f);
glRotatef(Zrotation,0.0f,0.0f,1.0f);
glRotatef(Yrotation,0.0f,1.0f,0.0f);

DrawCubeImage(fastFlag);

glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glFlush();

}

int DrawCubeImage(int fastFlag)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLineWidth(4.0);
glBegin(GL_LINES);

// X axel
glColor3f(1.0,0.0,0.0);
glVertex3f(0.0,0.0,0.0);
glVertex3f(5.0,0.0,0.0);

// Y Axel
glColor3f(0.0,0.0,1.0);
glVertex3f(0.0,0.0,0.0);
glVertex3f(0.0,5.0,0.0);

// Z Axel
glColor3f(1.0,1.0,1.0);
glVertex3f(0.0,0.0,0.0);
glVertex3f(0.0,0.0,5.0);

glEnd();
//glFlush();

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]); // Select my texture

glBegin(GL_QUADS);
glColor3f(0.0,1.0,1.0);
// Front face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom left of the texture and quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom right of the texture and quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top left of the texture and quad
// Back face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom right of the texture and quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top left of the texture and quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom left of the texture and quad
// Top face
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top left of the texture and quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom left of the texture and quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom right of the texture and quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top right of the texture and quad
// Bottom face
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top left of the texture and quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom left of the texture and quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom right of the texture and quad
// Right face
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom right of the texture and quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top left of the texture and quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom left of the texture and quad
// Left face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom left of the texture and quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom right of the texture and quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top right of the texture and quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top left of the texture and quad
glEnd();
return true;
}

Hope i can get some help!

Thanks!

/JH