i did that.
now texture is correctly fitting to my window.
but the problem is how to draw any objects on that.
once i bind the texture, i am drawing some moving lines . the problem is the color of texture is getting converted to whatever color i choose to draw line.
i am unable to figure it out.
pls help me out.
the code is as follows.
/*
Created by VC6-OGL
Main.cpp: Bitmap Loading
*/
#include <windows.h>
#include <gl/glut.h>
#include <gl/glu.h>
#include <gl/gl.h>
#include <stdio.h>
#include “Bitmap.h”
int w = 600,h = 500;
int sw, pw, cw, state = 0;
int hsiyaw[51]={50,50,50,50,50,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95};
static char stringlabel[100];
void drawstring (char *s)
{
unsigned int i;
for (i = 0; i < strlen (s); i++)
glutBitmapCharacter (GLUT_BITMAP_HELVETICA_18, s[i]);
}
void drawSmall (char *s)
{
unsigned int i;
for (i = 0; i < strlen (s); i++)
glutBitmapCharacter (GLUT_BITMAP_9_BY_15, s[i]);
}
void
idle (void)
{
float i = 0;
for (i = 0; i < 20000; i += 0.001)
{
}
if (state == 50)
state = 0;
state++;
glutSetWindow (cw);
glutPostRedisplay ();
}
void init( void )
{
if ( !LoadGLTextures() )
{
MessageBox( NULL, “Cannot Load - Background.bmp”, “Error”, MB_ICONINFORMATION | MB_OK );
exit( 0 );
}
glEnable( GL_TEXTURE_2D );
glClearColor ( 0.0, 0.0, 0.0, 0.0 ); // Clear Color - Black
glShadeModel ( GL_SMOOTH ); // Smooth Shade Model
//glEnable ( GL_DEPTH_TEST ); // Enable Depth Test
}
void
reshape (int w, int h)
{
// Prevent a divide by zero
if(h == 0)
h = 1;
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (-1.0, 1.0, -1.0, 1.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
}
void display( void )
{
int i = 0, j = 0;
glutSetWindow (pw);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glLoadIdentity ();
glPushMatrix();
glBindTexture( GL_TEXTURE_2D, texture[0] );
glBegin( GL_POLYGON );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -1.33, -1.0f, 0.5f );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.33, -1.0f, 0.5f );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.33, 1.0f, 0.5f );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -1.33, 1.0f, 0.5f );
glEnd();
glPopMatrix();
glColor3f (1.0, 0.0, 0.0);
glLineWidth (1.0);
glTranslatef (-(hsiyaw[state] * 0.1 * 0.4), 0.0, 0.0);
for (i = 0; i < 36; i += 1)
{
glBegin (GL_LINES);
glVertex2f (i * 0.40, 0.4);
glVertex2f (i * 0.40, -0.6);
glVertex2f (i * 0.20, -0.1);
glVertex2f (i * 0.20, 0.0);
glEnd ();
glRasterPos2f (i * 0.40, 0.6);
sprintf (stringlabel, “%d”, i);
drawSmall (stringlabel);
glFlush ();
}
j = 1;
for (i = 35; i >= 0; i -= 1)
{
glBegin (GL_LINES);
glVertex2f (-j * 0.40, 0.4);
glVertex2f (-j * 0.40, -0.6);
glVertex2f (-j * 0.20, -0.1);
glVertex2f (-j * 0.20, 0.0);
glEnd ();
glRasterPos2f (-j * 0.40, 0.6);
sprintf (stringlabel, “%d”, i);
drawSmall (stringlabel);
j += 1;
glFlush ();
}
glutSwapBuffers();
}
void keyboard( unsigned char key, int x, int y ) {
switch ( key ) {
case 27: // On ‘Esc’
exit( 0 ); // Quit
break;
}
}
void main( int argc, char **argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
glutInitWindowSize (w,h);
glutInitWindowPosition (150,10);
pw = glutCreateWindow (“Multi Function Display”);
init();
glutDisplayFunc( display );
glutReshapeFunc( reshape );
glutKeyboardFunc( keyboard );
glutIdleFunc (idle);
glutMainLoop();
}