I’m working on a 2d layout application which harbors rotatable and translatable elements (or example a square box). The application includes the abilityto magnify and translate the current view. These elements should contain ornaments (for example a 2d coordinate system) which should be translated and rotated but not never been scaled.
For this purpose I have defined small mipmaps (size 16x16) via gluBuild2Dmipmaps and bound them to textures (glBindTexture(GL_TEXTURE_2D…)
Using this texture via GL_QUADS works very well, but shows ugly results in case it is rotated. I wonder if texture mapping is the right approach for this purpose or if it is better to use other techniques?
This is the code snippet I’m using to create the texture:
glPixelStorei(GL_UNPACK_ALIGNMENT,4);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
// create the image
BYTE* pMemory = new BYTE[nSize];
....
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, bitmapColor.bmWidth, bitmapColor.bmHeight, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pMemory);
delete[] pMemory
This is the code snippet I’m using to draw the texture:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(m_dX, m_dY, 0);
glRotated(m_dAngle, 0, 0, 1);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glAlphaFunc(GL_GEQUAL, (GLclampf)1);
glEnable(GL_ALPHA_TEST);
glClearColor (0.0f, 0.0f, 0.0f, 0.5f);
glClearDepth (1.0f);g
glDepthFunc (GL_LEQUAL);
glDisable(GL_DEPTH_TEST);
glShadeModel (GL_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);
double dWidth = 16;
double dHeight = 16;
int nNumber = 1;
glBegin(GL_QUADS);
// top left
glTexCoord2d(0, nNumber);
glVertex3d(-dWidth/2.0, dHeight/2.0, 0);
// top right
glTexCoord2d(nNumber, nNumber);
glVertex3d(dWidth/2.0, dHeight/2.0, 0);
// bottom right
glTexCoord2d(nNumber, 0);
glVertex3d(dWidth/2.0, -dHeight/2.0, 0);
// bottom left
glTexCoord2d(0, 0);
glVertex3d(-dWidth/2.0, -dHeight/2.0, 0);
glEnd();
glDisable(GL_ALPHA_TEST);
glDisable(GL_TEXTURE_2D);
SwapBuffers(dc.m_hDC);