Sry about the last post :D my braind failed on me ..
so here is the deal .. i need a litle help ..
half of the program is done .. there are just mising parths .. if somone can fill them ? ( im just a begginer.. ) rest of the program is done rly hard.. with google and stuff :S
May the newbie power be with me ? :S
i just need to draw the body
the game needs to be simple..
just a body .. the place for the word to be guest.. and on the top of the monitor the incoret latters.
O
/I\
/ \
the word that needs to be set is SAKAM SEKSA ( two words actualy )
if the latter is corect when inserted.. then its shown on the monitor.. if its wrong a parth of the body is drawn.. .. simple hangman game..
you can se i marked from where i need the help .. ( it will take someone that knows this probably 10 min or less to finish the program )
you can ignore the top parth of the program ( check the down section from the red latters down ) .. its done.. just need to .. create Polygons probably.. ( for the arms.. legs and body ) any help ?
CodeGeneration -> Enable c++ exceptions = NO
#pragma warning(disable:4786)
#include <map>
using namespace std ;
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <glaux.h>
#include <glext.h>
#include <glut.h> //[I]glut file for windows[/I]
// [I]inludes gl.h and glu.h [/I]
#include<iostream>
#include<string>
// [I]picture is BMP 24 bits[/I]
BITMAPINFO *bginfo; // [I]Bitmap information[/I]
GLubyte *bgpixels; // [I]Actual pixel data[/I]
#pragma region Operacii so sliki
extern GLubyte * ReadBitmap(const char *filename,BITMAPINFO **info);
extern int SaveBitmap(const char *filename, BITMAPINFO *info,GLubyte *bits);
extern GLubyte * ReadBitmapFromScreen(BITMAPINFO **info);
/* read bitmap information. Returns the final bitmap pixel values */
GLubyte *
ReadBitmap(const char *filename,
BITMAPINFO **info)
{
FILE *fp; /* Open file pointer */
GLubyte *pixels; /* Bitmap pixel bits */
int imgsize; /* Size of bitmap image*/
int infosize; /* Size of header information */
BITMAPFILEHEADER header; /* File header */
// [I]Try opening the file; use "rb" mode to read a binary file. [/I]
if ((fp = fopen(filename, "rb")) == NULL)
return (NULL);
// [I]Read the file header[/I]
if (fread(&header, sizeof(BITMAPFILEHEADER), 1, fp) < 1)
{
// [I]Couldn't read the file header [/I]
fclose(fp);
return (NULL);
}
if (header.bfType != 'MB') /* 'MB' set to 'B' Check for BM reversed... */
{
// Not a bitmap file
fclose(fp);
return (NULL);
}
infosize = header.bfOffBits - sizeof(BITMAPFILEHEADER);
if ((*info = (BITMAPINFO *)malloc(infosize)) == NULL)
{
fclose(fp);
return (NULL);
}
if (fread(*info, 1, infosize, fp) < infosize)
{
free(*info);
fclose(fp);
return (NULL);
}
/* Now that we have all the header info read in, allocate memory for *
* the bitmap and read it in...
*/
imgsize = (*info)->bmiHeader.biSizeImage;
// sometimes imagesize is not set in files
if (imgsize == 0)
imgsize = ((*info)->bmiHeader.biWidth *
(*info)->bmiHeader.biBitCount + 7) / 8 *
abs((*info)->bmiHeader.biHeight);
if ((pixels = (unsigned char *)malloc(imgsize)) == NULL)
{
free(*info);
fclose(fp);
return (NULL);
}
if (fread(pixels, 1, imgsize, fp) < imgsize)
{
free(*info);
free(pixels);
fclose(fp);
return (NULL);
}
fclose(fp);
return (pixels);
}
/*
* 'SaveBitmap()' - Save a BMP file to disk.
*
* Returns 0 on success or -1 on failure...
*/
int
SaveBitmap(const char *filename, /* File to save to */
BITMAPINFO *info, /* Bitmap information */
GLubyte *bits) /*Bitmap data */
{
FILE *fp;
int size, infosize, bitsize;
BITMAPFILEHEADER header;
/* Try opening the file; use "wb" mode to write this *binary* file. */
if ((fp = fopen(filename, "wb")) == NULL)
return (-1);
/* Figure out the bitmap size */
if (info->bmiHeader.biSizeImage == 0)
bitsize =(int) ((info->bmiHeader.biWidth *
info->bmiHeader.biBitCount + 7) / 8 * fabs((double)info->bmiHeader.biHeight));
else
bitsize = info->bmiHeader.biSizeImage;
/* Figure out the header size */
infosize = sizeof(BITMAPINFOHEADER);
switch (info->bmiHeader.biCompression)
{
case BI_RGB :
if (info->bmiHeader.biBitCount > 8 &&
info->bmiHeader.biClrUsed == 0)
break;
}
size = sizeof(BITMAPFILEHEADER) + infosize + bitsize;
/* Write the file header, bitmap information, and bitmap pixel data... */
header.bfType = 'MB'; /*'MB' set to 'B' */
header.bfSize = size;
header.bfReserved1 = 0;
header.bfReserved2 = 0;
header.bfOffBits = sizeof(BITMAPFILEHEADER) + infosize;
if (fwrite(&header, 1, sizeof(BITMAPFILEHEADER), fp) < sizeof(BITMAPFILEHEADER))
{
/* Couldn't write the file header - return... */
fclose(fp);
return (-1);
}
if (fwrite(info, 1, infosize, fp) < infosize)
{
/* Couldn't write the bitmap header - return... */
fclose(fp);
return (-1);
}
if (fwrite(bits, 1, bitsize, fp) < bitsize)
{
/* Couldn't write the bitmap - return... */
fclose(fp);
return (-1);
}
fclose(fp);
return (0);
}
GLubyte *
ReadBitmapFromScreen(BITMAPINFO **info)
{
long i,j,bitsize, width;
GLint viewport[4];
GLubyte *bits;
GLubyte *rgb, tmp;
// [I]get the extents of the viewport of the window[/I]
glGetIntegerv(GL_VIEWPORT, viewport);
if ((*info = (BITMAPINFO *)malloc(sizeof(BITMAPINFOHEADER))) == NULL)
return NULL;
width = viewport[2]*3;
width = (width+3)& ~3;
bitsize = width*viewport[3];
if ((bits = (unsigned char *)calloc(bitsize,1)) ==NULL)
return NULL;
glPixelStorei(GL_PACK_ALIGNMENT,4);
glPixelStorei(GL_PACK_ROW_LENGTH,0);
glPixelStorei(GL_PACK_SKIP_ROWS,0);
glPixelStorei(GL_PACK_SKIP_PIXELS,0);
glReadPixels(0,0,viewport[2], viewport[3], GL_BGR_EXT, GL_UNSIGNED_BYTE,bits);
(*info)->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
(*info)->bmiHeader.biWidth = viewport[2];
(*info)->bmiHeader.biHeight = viewport[3];
(*info)->bmiHeader.biPlanes = 1;
(*info)->bmiHeader.biBitCount = 24;
(*info)->bmiHeader.biCompression = 0L; // BI_RGB;
(*info)->bmiHeader.biSizeImage = bitsize;
(*info)->bmiHeader.biXPelsPerMeter = 2952;
(*info)->bmiHeader.biYPelsPerMeter = 2952;
(*info)->bmiHeader.biClrUsed = 0;
(*info)->bmiHeader.biClrImportant = 0;
return(bits);
}
#pragma endregion Operacii so sliki
void PrintText(float x, float y, string text) {
glRasterPos2f(x, y);
for each(char c in text) {
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, c);
}
//[I]Font and font size[/I]
//[I]GLUT_BITMAP_8_BY_13[/I]
//[I]GLUT_BITMAP_9_BY_15[/I]
//[I]GLUT_BITMAP_TIMES_ROMAN_10[/I]
//[I]GLUT_BITMAP_TIMES_ROMAN_24[/I]
//[I]GLUT_BITMAP_HELVETICA_10[/I]
//[I]GLUT_BITMAP_HELVETICA_12[/I]
//[I]GLUT_BITMAP_HELVETICA_18[/I]
}
I NEED HELP FROM HERE TO THE END
// [I]routine to draw a circle approximated by line segments[/I]
void MyCircle2f(GLfloat centerx, GLfloat centery, GLfloat radius){
#define PI 3.1415926535898 // recall that cos and sin functions require angles in radians
// [I]2PI radians = 360 degrees, a full [/I]circle
GLint circle_points = 100;
GLint i;
GLdouble angle;
glBegin(GL_POLYGON);
for (i = 0; i < circle_points; i++) {
angle = 2*PI*i/circle_points;
glVertex2f(centerx+radius*cos(angle), centery+radius*sin(angle));
}
glEnd();
}
//[I]Change the dimensions of the window[/I]
void reshape (int w, int h)
{
// [I]on reshape and on startup, keep the viewport to be the entire size of the window[/I]
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
// [I]keep our logical coordinate system constant[/I]
gluOrtho2D(0.0, w, 0.0, h);
}
#pragma region Klasa HangMan i nejzini metodi
class HangMan
{
public:
HangMan(string word);
virtual ~HangMan();
void Draw();
void DrawHead(); //[I]Draw the head[/I]
void DrawLeftEye(); //[I]Draw the Left Eye[/I]
void DrawRightEye(); //[I]Draw the Right Eye[/I]
void DrawBody(); //[I]Draw the body[/I]
void DrawLeftArm(); //[I]Draw the Left Arm[/I]
void DrawRightArm(); //[I]Draw the Right Arm[/I]
void DrawLeftLeg(); //[I]Draw the Left Leg[/I]
void DrawRightLeg(); //[I]Draw the Right Leg[/I]
void SetWord(string w); //[I]Set the word to be guessed[/I]
void ContainLetter(char a); //[I]returns true if the meteor is out of screen this is from a diferent program so if its wrong correct it pls [/I]
GLint MissedLetters; //[I] unique ID to identify the meteor[/I]
private:
string wordtobeguessed; //
GLfloat location[2]; //
y-coordinate
};
HangMan::HangMan(string word){
wordtobeguessed = word;
MissedLetters = 0;
};
void HangMan::ContainLetter(char a){
string::size_type loc1 = wordtobeguessed.find( a, 0 );
if(loc1 != string::npos){
//check if the latter is in the word
// if the latter is in the word the latter is printet on the screan in the corect place
}else{
//if the latter is missing not in the word the latter shut be writen on the top of the screan in the missed latters
MissedLetters++;
}
};
void HangMan::SetWord(string w){
wordtobeguessed = w;
};
void HangMan::Draw(){
switch ( MissedLetters )
{
case 1:
DrawHead();
break;
case 2:
DrawHead();
DrawLeftEye();
break;
case 3:
DrawHead();
DrawLeftEye();
DrawRightEye();
break;
//in case if the latters 4,5,6 etc in the word then a parth of the body is draw
default:
//if all the parths of the body are drawn the game ends
//all the parths are drawn
//the word is shown
//game ends
PrintText(100, 120, wordtobeguessed);
break;
}
}
void HangMan::DrawHead(){
glColor3f(1.0f,0.0f,0.0f); //choasen collor
MyCircle2f(300, 300, 30); //draw head
};
void HangMan::DrawLeftEye(){
glColor3f(0.0f,0.0f,1.0f); //choasen collor
MyCircle2f(290, 300, 5); //draw left eye
};
void HangMan::DrawRightEye(){
glColor3f(0.0f,0.0f,1.0f); //choasen collor
MyCircle2f(310, 300, 5); //draw right eye
};
void HangMan::DrawLeftArm(){
glClearColor(1.0,0.0,0.0,1.0); //choasen collor
//dra left arm
};
void HangMan::DrawRightArm(){
glClearColor(1.0,0.0,0.0,1.0); //choasen collor
//draw right arm
};
void HangMan::DrawBody(){
glClearColor(1.0,0.0,0.0,1.0); //choasen collor
//draw body
};
void HangMan::DrawLeftLeg(){
glClearColor(1.0,0.0,0.0,1.0); //choasen collor
//draw left leg
};
void HangMan::DrawRightLeg(){
glClearColor(1.0,0.0,0.0,1.0); //choasen collor
//draw right leg
};
HangMan::~HangMan() {
wordtobeguessed = "";
MissedLetters = 0;
}
#pragma endregion Klasa HangMan i nejzini metodi
HangMan *hm = new HangMan("");
void Display(void)
{
//clear all pixels with the specified clear color
glClear(GL_COLOR_BUFFER_BIT);
//draw the background picture
// if (bgpixels){
//glRasterPos2f(0,0);
//glPixelZoom(1,1);
//glDrawPixels(bginfo-> bmiHeader.biWidth, bginfo-> bmiHeader.biHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, bgpixels);
// }
hm->Draw();
glFlush();
glutSwapBuffers();
}
void keyPressed (unsigned char key, int x, int y) {
hm->ContainLetter(key);
glutPostRedisplay();
}
void init(void){
//set the clear color to be white
glClearColor(1.0,1.0,1.0,1.0);
glLineWidth(5.0);
// polygons drawn should be filled
glPolygonMode(GL_FRONT, GL_FILL);
glutKeyboardFunc(keyPressed); // Tell GLUT to use the method "keyPressed" for key presses
}
int main(int argc, char* argv[])
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (600, 600);
glutCreateWindow("HangMan Game");
//read the backgruond picture
bgpixels = ReadBitmap("HangManBackgruond.bmp", &bginfo);
//set the word that needs to be guest the word needs to be SAKAM SESKA
hm->SetWord("Proba");
init();
glutDisplayFunc(Display);
glutReshapeFunc(reshape);
glutMainLoop();
}