• Advertisement
Sign in to follow this  

Pong

This topic is 4681 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have earlier programmed in Allegro and it was very easy, now I want to move up to something more professional, still crossplatform. I choosed OpenGL and it seemed hard. So, can i have the sourcecode for a Pong game, it would be helpful to se how input, processing, output and gamestates work, I think I can use a sourcecode to learn. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Allegro = all the things you just asked for
OpenGL = Open Graphics Library. It does graphics.

Look up SDL, which will do everything else :)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
no. you can only handle graphics using OpenGL; hence the name, Open Graphics Language.

Share this post


Link to post
Share on other sites
Ok sorry.

But what about


if (keys[VK_RIGHT])
{
//Do stuff
}

?

Found it in an NeHe guide...

Share this post


Link to post
Share on other sites
Quote:
Original post by Neoecs
Ok sorry.

But what about


if (keys[VK_RIGHT])
{
//Do stuff
}

?

Found it in an NeHe guide...


That's some Win32 input handling, not something provided by OGL.

Share this post


Link to post
Share on other sites
Ok, can I use that? I guess it wont work on other OS'es that Windows if i do? Is it fast? Is it good?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
lol, VK_RIGHT VK_LEFT, are winapi virtual keys, constants defined in the windows headers. if you were wanting to make a cross platform game you would have to make a generic interface to the input.

If your a making a pong game I wouldn't be worrying about portability, unless it's a next gen version.

Share this post


Link to post
Share on other sites
you are going to learn win32 programming in addition to opengl? as a beginner, might i suggest you try glut, freeglut or glfw ... all of which provide means for simple input handling (keyboard and mouse). that way you can learn opengl without worrying about the details of win32 programming... which in and off itself can be a daunting task for the 'young jedi in training'. others might suggest SDL, but as 'simple' as it is ... the others i mentioned are even easier to get up and running (assuming you know how to link in external libs and add a new header reference).

Share this post


Link to post
Share on other sites
Quote:
Original post by Neoecs
Ok, can I use that? I guess it wont work on other OS'es that Windows if i do?


Bingo, got it in one. Works perfectly fine, but only on Windows as you guessed. You might want to look at SDL; It's cross platform, and has input handling, sound, and rendering (and can be used for window handling along with OGL for 3d). Alternately, Screwtape's suggestions are an excellent way to get yourself some simple input handling along with OGL.

Share this post


Link to post
Share on other sites
[EDIT] to slow... I'm going to try Glut! Thank you all!

[EDIT2] Should I use Glut or SDL? Which one is best/fastest and so on?

Share this post


Link to post
Share on other sites
I love the last two posts... the second one is such a wonderful follow up to the first... the timing, the simplicity...

DirectX is not cross platform - OpenGL and SDL, which make a rather snazzy combination, are. Allegro is too.

Out of curiosity, I've never used Allegro, but what causes you to imply that it is "unprofessional" ?

Share this post


Link to post
Share on other sites
Quote:
Original post by Squirm
I've never used Allegro, but what causes you to imply that it is "unprofessional" ?


He raises a good point (albeit somewhat accidentally), there's nothing wrong with using Allegro really. Learning new stuff is also good too though of course.

As for tutorials, there are links to a few in each of several commonly used APIs in the For Beginners Forum FAQ, and I'm willing to bet Google knows a few more. [wink] Pick an API, and learn it, you'll never get anything done if you sit around thinking about which one to use constantly.

Share this post


Link to post
Share on other sites
Why Allegro is unpro?.. Dunno =P
Of course DirectX is crossplatform, it's made by Micro$oft..

Will i need to learn Win32Api to use OpenGL + SDL?


Anyway: I've decided to use OpenGL + SDL.

Thank you all.

Share this post


Link to post
Share on other sites
Quote:
Original post by Neoecs
Will i need to learn Win32Api to use OpenGL + SDL?


No.

Quote:

Of course DirectX is crossplatform, it's made by Micro$oft..

No, it's not cross platform, specifically because it's made by Microsoft, for thier own OS.

Don't bash MS though, they make pretty decent software, they're better developers than you at the moment, and they're definately very good at marketting, nothing to disrespect 'em for there.

OpenGL + SDL is an excellent choice, it should do everything you need - good luck with it.

Share this post


Link to post
Share on other sites
Sorry, i wrote wrong :D
I was about to write "of cource it's NOT crossplatform because it's made by Micro$oft"... xD

But SDL's homepage doesn't say anything about windowhandling..

Share this post


Link to post
Share on other sites
Quote:
But SDL's homepage doesn't say anything about windowhandling


SDL_Init();
SDL_VideoMode(800,640,32,flags);

tada! A window :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Squirm
Quote:
But SDL's homepage doesn't say anything about windowhandling


SDL_Init();
SDL_VideoMode(800,640,32,flags);

tada! A window :)


Thank you! Weird that they didn't write that on the feauture list =D

Share this post


Link to post
Share on other sites
Well, it's not so much a feature as something you just need to do. It just so happens that SDL does it quite simply.

Share this post


Link to post
Share on other sites
Sorry for bumping up an old thread, but when i compile the code


#include "SDL.h"

int main(int argc, char *argv[])
{

if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

{ SDL_Surface *screen;

screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE);
if ( screen == NULL ) {
fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}
}

return 0;
}


It wont work, I get the errors

--------------------Configuration: SDL_test - Win32 Debug--------------------
Compiling...
main.cpp
C:\Program\Microsoft Visual Studio\MyProjects\SDL_test\main.cpp(8) : error C2065: 'exit' : undeclared identifier
Error executing cl.exe.

SDL_test.exe - 1 error(s), 0 warning(s)


And when I comment away all the code betwen main{ and } it gives me the errors

--------------------Configuration: SDL_test - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
msvcrt.lib(MSVCRT.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_SetModuleHandle
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_Quit
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_GetError
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_Init
Debug/SDL_test.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

SDL_test.exe - 9 error(s), 1 warning(s)

What hav I done wrong?

Thank you.

Share this post


Link to post
Share on other sites
Quote:
error C2065: 'exit' : undeclared identifier

#include <stdlib.h>

The rest of the errors are because you haven't linked SDL to your project.

Share this post


Link to post
Share on other sites
Thank you! That helped some.. But.. What about "Cant execute Link.exe"?

--------------------Configuration: SDL_test - Win32 Debug--------------------
Compiling...
main.cpp
Linking...
msvcrt.lib(MSVCRT.dll) : error LNK2005: _exit already defined in LIBCD.lib(crt0dat.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _strncpy already defined in LIBCD.lib(strncpy.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: _fclose already defined in LIBCD.lib(fclose.obj)
msvcrt.lib(MSVCRT.dll) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LIBCD.lib(crt0init.obj) : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_SetModuleHandle
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_Quit
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_GetError
SDLmain.lib(SDL_win32_main.obj) : error LNK2001: unresolved external symbol _SDL_Init
Debug/SDL_test.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

SDL_test.exe - 9 error(s), 1 warning(s)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement