C++ 2D Game Engine

Pages: 12
But that's the thing, he's not "really getting into" game programming, he's just using a prebuilt engine.

When he wants to take the next step, then yeah he'll probably need to know this stuff. But telling it to him now is pointless. It will just confuse/overload him and doesn't do anything to help him with his immediate goal.
I'm not going to assume he cannot grasp it or that its too much for him. Best he knows all the info then make a decision from there. That's my thinking.


I guess we will agree to disagree. :)
Anyway, I think lets just let the OP decide what he wants to do next. In the end, it's really up to him what he wants to do.

@WinwordExonar I think the terrain you made in OpenGL is quite cool, you made all that from scratch?
Fair enough
Yes I did. And it was a learning experience let me tell ya. And that has an undertone of DirectX API built in so it will not work on Linux or MAC. I am switching from writing that in BASIC to using C++ now.

Its another reason I choose OpenGL as my graphics API. Even if I did use an engine like Ogre, I now know how Ogre works because I studied the API's that were being called by the engines. I want my future game(s) to have no limits.
Last edited on
I now know how Ogre works because I studied the API's that were being called by the engines

I see, that must have taken quite a while to learn throughout. I was studying Direct X before and it takes quite a while to grasp everything to be honest. Well and if you stop practicing you forget almost everything all over again. Maybe that's just me though. lol

I want my future game(s) to have no limits.

no limits? wouldn't software always be limited by the hardware though?
no limits? wouldn't software always be limited by the hardware though?


It Depends. With DirectX your limited yes, because it only works on Microsoft platforms. Not linux ( although some have tried with a few open source projects out there, but none have really 100% succeeded ) or phone apps ( unless its from microsoft ) or MAC.

However, with OpenGL, there is no limits in making anything you want for any platform except the XBOX. The issue as some are saying here on this thread is that the OP doesn't want to work with API. I get that and in a way I totally agree with what people are saying. It really is a PAIN IN THE @#$@#$... but.. in the end, you'll end up back learning that you must choose which API your going to want to use. You will have no choice because like windows DLLs, each API has its own set of functions that ALL game engines need to call.

By the way Dacster13, my demo was made using DarkBasic Pro which calls the Windows DirectX API. And yes, I had to KNOW that it was using DirectX and that there were a few DirectX API calls I HAD to know just to make it work. Just making sure you understand that. And as for OpenGL, I have been pouring my heart into it once I figured it out. I have all kinds of examples on my computer that work with OpenGL now.
Last edited on

@Disch and Win: I appreciate the help guys. I did some more research and I changed my mind about using a prebuilt game engine. I'll give OpenGL a try after getting a little more into Allegro 5. After all, Allegro can be used along with OpenGL... and the they're both cross-platform! XD

@Win: I'll check out the book you recommended about OpenGL. If it's easy enough to understand, I might just focus on learning OpenGL directly. If I find it too hard to grasp, then I'd have to go with Allegro for the meantime since I would like to be highly familiar with 2D before even attempting to get near 3D. Thanks again.
Actually Allegro 5 AND openGL can be used at the same time. But yes, stick with one at a time to understand how it all works. I mean I myself have been eyeing Allegro. But I wanted to learn OpenGL first so that I could understand Allegro. Sad I know.. lol

As for OpenGL, you will come across the fact that you will want the Glut / Glut32 Libraries in that book. Just change out the libraries to using freeGlut instead, but you can still keep the Glut commands. Its the replacement for the OLD 2001 Glut / Glut32 versions. Open Source too. Latest versions that I am aware of for freeGlut is 2010. So its up to date for the most part.

Here is a lot of tutorials on how to use OpenGL in general : http://www.videotutorialsrock.com

I have personally tested that guys code and it works perfectly if you fix one of the lines he has in there.

Here is an example of his code that works from his site and I used Code::Blocks IDE with freeGlut.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above notice and this permission notice shall be included in all copies
 * or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
/* File for "Basic Shapes" lesson of the OpenGL tutorial on
 * www.videotutorialsrock.com
 */



#include <iostream>
#include <stdlib.h> //Needed for "exit" function

//Include OpenGL header files, so that we can use OpenGL
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

//Called when a key is pressed
void handleKeypress(unsigned char key, //The key that was pressed
					int x, int y) {    //The current mouse coordinates
	switch (key) {
		case 27: //Escape key
			exit(0); //Exit the program
	}
}

//Initializes 3D rendering
void initRendering() {
	//Makes 3D drawing work when something is in front of something else
	glEnable(GL_DEPTH_TEST);
}

//Called when the window is resized
void handleResize(int w, int h) {
	//Tell OpenGL how to convert from coordinates to pixel values
	glViewport(0, 0, w, h);

	glMatrixMode(GL_PROJECTION); //Switch to setting the camera perspective

	//Set the camera perspective
	glLoadIdentity(); //Reset the camera
	gluPerspective(45.0,                  //The camera angle
				   (double)w / (double)h, //The width-to-height ratio
				   1.0,                   //The near z clipping coordinate
				   200.0);                //The far z clipping coordinate
}

//Draws the 3D scene
void drawScene() {
	//Clear information from last draw
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
	glLoadIdentity(); //Reset the drawing perspective

	glBegin(GL_QUADS); //Begin quadrilateral coordinates

	//Trapezoid
	glVertex3f(-0.7f, -1.5f, -5.0f);
	glVertex3f(0.7f, -1.5f, -5.0f);
	glVertex3f(0.4f, -0.5f, -5.0f);
	glVertex3f(-0.4f, -0.5f, -5.0f);

	glEnd(); //End quadrilateral coordinates

	glBegin(GL_TRIANGLES); //Begin triangle coordinates

	//Pentagon
	glVertex3f(0.5f, 0.5f, -5.0f);
	glVertex3f(1.5f, 0.5f, -5.0f);
	glVertex3f(0.5f, 1.0f, -5.0f);

	glVertex3f(0.5f, 1.0f, -5.0f);
	glVertex3f(1.5f, 0.5f, -5.0f);
	glVertex3f(1.5f, 1.0f, -5.0f);

	glVertex3f(0.5f, 1.0f, -5.0f);
	glVertex3f(1.5f, 1.0f, -5.0f);
	glVertex3f(1.0f, 1.5f, -5.0f);

	//Triangle
	glVertex3f(-0.5f, 0.5f, -5.0f);
	glVertex3f(-1.0f, 1.5f, -5.0f);
	glVertex3f(-1.5f, 0.5f, -5.0f);

	glEnd(); //End triangle coordinates

	glutSwapBuffers(); //Send the 3D scene to the screen
}

int main(int argc, char** argv) {
	//Initialize GLUT
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(400, 400); //Set the window size

	//Create the window
	glutCreateWindow("Basic Shapes - videotutorialsrock.com");
	initRendering(); //Initialize rendering

	//Set handler functions for drawing, keypresses, and window resizes
	glutDisplayFunc(drawScene);
	glutKeyboardFunc(handleKeypress);
	glutReshapeFunc(handleResize);

	glutMainLoop(); //Start the main loop.  glutMainLoop doesn't return.
	return 0; //This line is never reached
}



Remember, there is a difference here that you MUST know. Glut / Glut32 / freeGlut are nothing more then wrappers to make your life easier when it comes to talking directly to the OpenGL API. You can even get to a point that you can make your own graphics engine without ever needing the wrappers if your dedicated enough.

Good luck to you sir.
Last edited on

Thank you for the tips Win. I appreciate it. If you actually decide you'd want to Allegro on your arsenal, I found this really cool website (http://fixbyproximity.com) that offers tutorials. I'm learning a lot from this guy.
You mean this link ? : http://fixbyproximity.com

And thank you for this. I been wondering about Allegro to make my OpenGL easier to use. FreeGlut has been my wrapper of choice, but Allegro looks to be just as good too. Again thank you. :)

Yeah, that's the one. Thanks too.
Disch's original suggestion for SFML is also a good (and free) choice. It is the one I have been using and I am pretty happy with it.
I also want to re-recommend SFML. OpenGL is great, but it's only graphics. When you want to do audio and joypads and stuff you'll want another lib.

SFML has all that other stuff, and lets you use OpenGL for graphics.
I am not sure to understand the real difference between an engine and a library. Is the difference just a matter of level ?

Well, if you need a low-level API, then OpenGL is the best choice you can make, as the most popular Operating Systems support it, so your game will be portable. However, these are really low-level and you have to do anything by yourself. That's why I suggest taking something of a higher-level without to come to a fully managed engine such as Irrlicht or Ogre3D. SDL is a good thing, as it provides a low-level API which allows to do nice things easily yet it is slower that the well-known SFML.

Finally, I think the choice is just a matter of taste, yet you must also know if you are ready and able to do the high-level GFX by yourself, such as beautiful light effects, fadings, or whatever. I'd myself prefer a managed engine.
There is also a good compromise that consists in using a low-level API but taking extracts from a big libary (but beware to the licenses of these libraries) such as SFML, SDL or whatever. Like that, you can take effects and create functions using this code. Anyway, if you need some light management, I know a good software which was created to help those who can't program by themselves (aka beginners) to create their games easily. It has a SDK to create extensions for this soft or to insert C++ code into the game. The SDK contains the official extensions and in them, there is a light management extension which you can take the code of. All you need is just not to ownership the creation of this code. Although the site is partially in French (I am myself a froggy ;) ), ther eis a part in English and also a version of this soft in English yet this English seems to be the output of some bad traducer, or the work of some pupil never learning his lessons, but what interests us is just the code for the extension, not the software by itself. Here are the links (the software's name is Game Develop) :

http://www.forum.compilgames.net/viewforum.php?f=27 (Dunno where is the link for the SDK but it must be easy to find ;)
Topic archived. No new replies allowed.
Pages: 12