hello guys, i want my code to display the raw image "texture.raw", and at the same time, display a flashing text exactly besides it in a seperate viewport or with some other way. Please help me with this, as this code doesnt do that, it just flashes the image and doesnt display the text. Please check the bold part in display method, i think thats where things are wrong...but i don;t know since i m a newbie.
#include "stdafx.h"
#include <stdlib.h>
#include "glut.h"
#include <windows.h>
#include <stdio.h>
//---
int frame=0;
int frame3=0;
int no_points=74;
float sx=1.0, sy=1.0, sx2=1.0,sy2=1.0, sx3=1.0,sy3=1.0, sx4=1.0,sy4=1.0, sx5=1.0,sy5=1.0;
const GLfloat colors[][3] = {
{ 255.0/255.0, 0.0/255.0, 0.0/255.0},
{ 128.0/255.0, 0.0/255.0, 0.0/255.0},
{ 205.0/255.0, 0.0/255.0, 0.0/255.0},
{ 0.0/255.0, 255.0/255.0, 0.0/255.0},
{ 0.0/255.0, 128.0/255.0, 0.0/255.0},
{ 0.0/255.0, 205.0/255.0, 0.0/255.0},
{ 0.0/255.0, 0.0/255.0, 255.0/255.0},
{ 0.0/255.0, 0.0/255.0, 128.0/255.0},
{ 0.0/255.0, 0.0/255.0, 205.0/255.0},
{ 255.0/255.0, 255.0/255.0, 0.0/255.0},
{ 128.0/255.0, 128.0/255.0, 0.0/255.0},
{ 205.0/255.0, 205.0/255.0, 0.0/255.0},
{ 0.0/255.0, 255.0/255.0, 255.0/255.0},
{ 0.0/255.0, 128.0/255.0, 128.0/255.0},
{ 0.0/255.0, 205.0/255.0, 205.0/255.0},
{ 255.0/255.0, 0.0/255.0, 255.0/255.0},
{ 128.0/255.0, 0.0/255.0, 128.0/255.0},
{ 205.0/255.0, 0.0/255.0, 205.0/255.0},
};
void renderSpacedBitmapString(float x, float y, int spacing, void *font, char *string)
{
char *c;
int x1=x;
for (c=string; *c != '\0'; c++) {
glRasterPos2f(x1,y);
glutBitmapCharacter(font, *c);
x1 = x1 + glutBitmapWidth(font,*c) + spacing;
}
}
void text1()
{
glColor3f(colors[frame3][0],colors[frame3][1],colors[frame3][2]);
frame3+=1;
renderSpacedBitmapString(130,200,1,GLUT_BITMAP_TIMES_ROMAN_24,"Food & Drink");
if(frame3>18) frame3=0;
}
//----
GLuint texture; //the array for our texture
GLfloat angle = 0.0;
int x;
//function to load the RAW file
GLuint LoadTexture( const char * filename, int width, int
height )
{
GLuint texture;
unsigned char * data;
FILE * file;
//The following code will read in our RAW file
file = fopen( filename, "rb" );
if ( file == NULL ) return 0;
data = (unsigned char *)malloc( width * height * 3 );
fread( data, width * height * 3, 1, file );
fclose( file );
glGenTextures( 1, &texture ); //generate the texture with
glBindTexture( GL_TEXTURE_2D, texture ); //bind the texture
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
GL_MODULATE ); //set texture environment parameters
//The qualities are (in order from worst to best)
//GL_NEAREST
//GL_LINEAR
//GL_LINEAR_MIPMAP_NEAREST
//GL_LINEAR_MIPMAP_LINEAR
//And if you go and use extensions, you can use Anisotropic
//even better quality, but this will do for now.
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
GL_LINEAR );
//Here we are setting the parameter to repeat the texture
//to the edge of our shape.
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
GL_REPEAT );
//Generate the texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0,
GL_RGB, GL_UNSIGNED_BYTE, data);
free( data ); //free the texture
return texture; //return whether it was successfull
}
void FreeTexture( GLuint texture )
{
glDeleteTextures( 1, &texture );
}
void square (void) {
glBindTexture( GL_TEXTURE_2D, texture ); //bind our texture
glBegin (GL_QUADS);
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0); //with
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0); //so that
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);
glEnd();
//This is how texture coordinates are arranged
//
// 0,1 —– 1,1
// | |
// | |
// | |
// 0,0 —– 1,0
// With 0,0 being the bottom left and 1,1 being the top right.
// brick walls.
}
void display (void) {
glClearColor (0.0,0.0,0.0,1.0);
glClear (GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glViewport (150, 30, (GLsizei)700, (GLsizei)500);
glEnable( GL_TEXTURE_2D );
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
square();
glutSwapBuffers();
angle ++;
//-------------------------
[B] //glMatrixMode (GL_PROJECTION);
//glLoadIdentity();
glViewport(0,0,(GLsizei)800,(GLsizei)600);
text1();
[/B]
}
void reshape (int w, int h) {
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (70, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode (GL_MODELVIEW);
}
int main (int argc, char **argv) {
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE);
glutInitWindowSize (800, 600);
glutInitWindowPosition (100, 100);
glutCreateWindow ("A basic OpenGL Window");
glutDisplayFunc (display);
glutIdleFunc (display);
glutReshapeFunc (reshape);
//Load our texture
texture = LoadTexture( "texture.raw", 256, 256 );
glutMainLoop ();
//Free our texture
FreeTexture( texture );
return 0;
}