Matching puzzle game

The pair matching memory game using OpenGL

Page 1 of 1

6 Replies - 5312 Views - Last Post: 17 May 2010 - 08:17 AM Rate Topic: -----

#1 RCL0000ZK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-March 10

Matching puzzle game

Posted 23 March 2010 - 10:33 AM

Hello,

I want to program the pair matching game in OpenGL. I am using Visual Studio 2008 for this.

The game is pretty common. It consists of a grid of tiles. Under each tile there will be a picture.

The picture is revealed for a short amount of time when the user clicks on it.

The goal of the player is to successively click on a pair of similar image tiles.

It is the same as the game found here.


Now, Since I know a bit of C and C++, I'm planning to implement using OpenGL. I will program the logic myself.



I wish to use external pictures to be read and displayed in place of hidden picture.

The program must be able to read it from a folder which contains all the pictures (which could be replaced each time before running exe file)

I have no experience in the external file reading and writing.

So, please help me with the code to read external images. Something that uses OpenGL would be preferred (I think it will be simpler).

The format of image is no problem (jpg, tiff, bmp or anything which is easier to handle).

Thank you.

This post has been edited by RCL0000ZK: 23 March 2010 - 10:38 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Matching puzzle game

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9265
  • View blog
  • Posts: 34,756
  • Joined: 12-June 08

Re: Matching puzzle game

Posted 23 March 2010 - 01:14 PM

View PostRCL0000ZK, on 23 March 2010 - 11:33 AM, said:

Hello,

I want to program the pair matching game in OpenGL. I am using Visual Studio 2008 for this.

The game is pretty common. It consists of a grid of tiles. Under each tile there will be a picture.

The picture is revealed for a short amount of time when the user clicks on it.

The goal of the player is to successively click on a pair of similar image tiles.

It is the same as the game found here.


Now, Since I know a bit of C and C++, I'm planning to implement using OpenGL. I will program the logic myself.



I wish to use external pictures to be read and displayed in place of hidden picture.

The program must be able to read it from a folder which contains all the pictures (which could be replaced each time before running exe file)

I have no experience in the external file reading and writing.

So, please help me with the code to read external images. Something that uses OpenGL would be preferred (I think it will be simpler).


The format of image is no problem (jpg, tiff, bmp or anything which is easier to handle).

Thank you.


You are looking to hard code the file locations? Mkay.. that seems a bit odd. Is that required for the assignment?

Additionally you won't be writing to files so half your research is already done!

Here's a link to loading bmp images:
http://www.gamedev.n...article1966.asp
Was This Post Helpful? 1
  • +
  • -

#3 RCL0000ZK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-March 10

Re: Matching puzzle game

Posted 08 May 2010 - 04:48 AM

View Postmodi123_1, on 23 March 2010 - 12:14 PM, said:

You are looking to hard code the file locations? Mkay.. that seems a bit odd. Is that required for the assignment?

Additionally you won't be writing to files so half your research is already done!

Here's a link to loading bmp images:
http://www.gamedev.n...article1966.asp


First of all, this is a late reply because I hadn't actually started the project. Now I'm at full speed ahead.

Yes, I want to hard code the files.
I'm planning to put a bunch of images in a folder (say, some pictures of cars in one folder). Have several folders like that (say car, bikes, etc.)
Now, I want to provide options in the initial program (c exe console) to select the category which you want and lode the images appropriately for each block in the game.


@modi123_1
The link which you have provided is very useful. Thankyou for that. But, the info in that is too much for a rookie like me. Its hard to understand. :( So please help.

Say I want to display the pictures car1.bmp, car2.bmp and car2.bmp in the three boxes in the following program, how do I do it?

#include<GL/glut.h>

void display();
void myReshape(int w,int h);

void main(int argc,char **argv)
{
	glutInit(&argc,argv);
	glutInitWindowSize(800,600);
	glutInitWindowPosition(0,0);
	glutCreateWindow("PointLinePlygon");
	glutReshapeFunc(myReshape);
	glutDisplayFunc(display);
	glEnable(GL_DEPTH_TEST);
	glutMainLoop();
}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glClear(GL_DEPTH_BUFFER_BIT);

	glClearColor(0,0,0,0);


	glBegin(GL_POLYGON);
		glColor3f(1,0,0);
		glVertex2f(-5,5);
		glVertex2f(0,5);
		glVertex2f(0,0);
		glVertex2f(-5,0);
	glEnd();

	glBegin(GL_POLYGON);
		glColor3f(0,1,0);
		glVertex2f(0,5);
		glVertex2f(5,5);
		glVertex2f(5,0);
		glVertex2f(0,0);
	glEnd();

	glBegin(GL_POLYGON);
		glColor3f(0,0,1);
		glVertex2f(0,0);
		glVertex2f(5,0);
		glVertex2f(5,-5);
		glVertex2f(0,-5);
	glEnd();

	glFlush();
}

void myReshape(int w,int h)
{
	glViewport(0,0,w,h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	if(w<=h)
		glOrtho(-10,10,-10*(GLfloat)h/(GLfloat)w,10*(GLfloat)h/(GLfloat)w,-20,20);
	else
		glOrtho(-10*(GLfloat)w/(GLfloat)h,10*(GLfloat)w/(GLfloat)h,-10,10,-20,20);
	glMatrixMode(GL_MODELVIEW);
	glutPostRedisplay();
}


Was This Post Helpful? 0
  • +
  • -

#4 RCL0000ZK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-March 10

Re: Matching puzzle game

Posted 10 May 2010 - 09:45 AM

*bump*
Was This Post Helpful? 0
  • +
  • -

#5 RCL0000ZK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 23-March 10

Re: Matching puzzle game

Posted 10 May 2010 - 11:10 AM

Using this, I made the following code.

However, it is not compiling. What am I doing wrong?

// pixmap.cpp

#include "pixmap.h"

#include <fstream>
#include <iostream>
#include <cstdlib>

#include <GL/glut.h>

	

pixmap::pixmap(const char *fname)
	: width(0), height(0), data(0)
{
	this->read(fname);
}

pixmap::pixmap()
	: width(0), height(0), data(0) {}

pixmap::~pixmap()
{
	if( data )
		delete[] data;
}

void pixmap::read(const char *fname)
{
	using namespace std;

	unsigned short planes;	// number of planes in image (must be 1) 
	unsigned short bpp;			// number of bits per pixel (must be 24)

	ifstream fin(fname, ios::in | ios::binary);
	if( !fin )
	{
		cerr << "File not found " << fname << '\n';
		exit(1);
	}
  
	fin.seekg(18, ios::cur);

	fin.read((byte *)&width, sizeof(unsigned));
	fin.read((byte *)&height, sizeof(unsigned));
	cout << "width: " << width << " height: " << height << '\n';

	fin.read((byte *)&planes, sizeof(unsigned short));
	if( planes != 1 )
	{
		cout << "Planes from " << fname << " is not 1: " << planes << "\n";
		exit(1);
	}

	fin.read((byte *)&bpp, sizeof(unsigned short));
	if( bpp != 24 )
	{
		cout << "Bpp from " << fname << " is not 24: " << bpp << "\n";
		exit(1);
	}
	
	fin.seekg(24, ios::cur);

	unsigned size(width * height * 3);				// size of the image in bytes (3 is to RGB component).
	data = new ubyte[size];
	fin.read((byte *)data, size);

	ubyte tmp;					// temporary color storage for bgr-rgb conversion.
	for( int i(0); i < size; i += 3 )
	{
		tmp = data[i];
		data[i] = data[i+2];
		data[i+2] = tmp;
	}
}

ubyte pixmap::pixel_elem(int x, int y, int elem)
{
	int pos = (y*width+x) * 3 + elem;
	return data[pos];
}

ubyte *pixmap::pixel_pos(int x, int y)
{
	int pos = (y * width + x) * 3;
	return &data[pos];
}

void display()
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glDrawPixels(img->width, img->height, GL_RGB, GL_UNSIGNED_BYTE, img->data);

  glutSwapBuffers();
}


void main(int argc, char** argv) {
  
pixmap img("untitled.bmp");

  glutInit(&argc, argv);
  //img->pixmap("untitled.bmp");

  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
  glutInitWindowSize(800, 600);
  glutCreateWindow("OpenGL glDrawPixels demo");

  glutDisplayFunc(display);
  //glutReshapeFunc(reshape);
  //glutMouseFunc(mouse_button);
  //glutMotionFunc(mouse_motion);
  //glutKeyboardFunc(keyboard);
  //glutIdleFunc(idle);
  
  glEnable(GL_DEPTH_TEST);
  glClearColor(0.0, 0.0, 0.0, 1.0);
  //glPointSize(2);

  glutMainLoop();
}


Was This Post Helpful? 0
  • +
  • -

#6 Guest_ZOMBIE!!!*


Reputation:

Re: Matching puzzle game

Posted 14 May 2010 - 02:16 PM

Im not exactly sure about the rules here. But im pretty sure there is no "Bumping" allowed
Was This Post Helpful? 0

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9265
  • View blog
  • Posts: 34,756
  • Joined: 12-June 08

Re: Matching puzzle game

Posted 17 May 2010 - 08:17 AM

Not compiling? what's the error messages?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1