PDA

View Full Version : getting my stuff together



sacros
09-03-2012, 11:14 AM
hey everyone

I hope im posting in the right section since im asking general questions and i probably cant get more general than what im gonna ask

Basically im an engineer student an i had my first fully procedural-only programming course this year with pascal and i loved it; Problem is i was taught mainly files and pointers-structure handling algorithms but for making games Im clueless of where to start.

So I felt maybe you guys could point me towards the right direction, i mean, i didnt even know how to use something that wasnt the command line for making stuff AND I STILL sort of dont.

Im leaning towards using OpenGL stuff like glut but then everyone playing in windows would have to install the glut32.dll right? and that sucks...

Maybe i should just grab a game engine? im assuming then that a game engine is a simplified means for making games (maybe not?) and i was going the wrong way? i dont even know...

any advise is greatly appreciated, thank yall

TL;DR: im n00b, know basics, where start advise pl0x

code_glitch
09-03-2012, 08:24 PM
Depends on how much/what you have experience with. If you're starting from zero - I'd have no issues recommending SDL. Glut can be problematic as it is rather dated now, but since its' grub time - i'll fill you in on anything more specific if you need, once I get my share! :D

sacros
12-03-2012, 02:15 AM
lol i just can use the language so thats my experience, im reading tuts on SDL thanks for that, i knew the graph unit wasnt gonna cut it for long :P

this SDL thing is wonderful and easy to use, i just wish the compiler didnt complain so much now :( oh well, ill stop being retarded one of these days

Ñuño Martínez
13-03-2012, 07:03 PM
GLUT was created as a fast&dirty library to test OpenGL stuff. It's great for fast prototyping but not for final work.

Currently I'm working in the wrapper to use the Allegro 5 library with Pascal (Allegro is a library similar than SDL but with different approach) and it's able to start an OpenGL context too. Windows works with issues (can't deal with pixel and text stuff yet) but OpenGL initialization, texture loading, user input, sound and time control seems to work. Linux works much better (as far as I can see, only prototype-drawing doesn't work correctly).

I tell you just to show you an alternative to SDL.

sacros
14-03-2012, 02:02 AM
cool, that helped, for some reason i get an error with SDL from the compiler complaining about needing a unit and interface before "program" stuff and i dont even know what that is, guess its some of them fancy stuff from object oriented programming but OOP is out of my reach at least for this year

so im actually downloading allegro.pas as i write to give it a try. sounds like one hell of a library and one hell of a project; id love to know what you mean by "there is pixel handling issues in windows", is it like it has problems working with single pixels or is it something with raster based stuff in general? id love to use allegro with my ubuntu installation but the free pascal compiler distributed in the software center is completely broken and i couldnt find a way to install it from rpm packages (yhea, im a n00b in linux too) so windows it is

User137
14-03-2012, 05:48 AM
cool, that helped, for some reason i get an error with SDL from the compiler complaining about needing a unit and interface before "program" stuff and i dont even know what that is, guess its some of them fancy stuff from object oriented programming but OOP is out of my reach at least for this year
Nope. It sounds like a basic level programming error, similar to this code would tell something crazy ;D

then a=b if
You'll always get help if you ask though, but then you need to refer the full error and part of the source code.

sacros
14-03-2012, 11:03 PM
thanks for the offer user137, i appreciate your help, i just wish you werent such an asshole with your " a=b " shit

the problem is the compìler ask for "interface" or "unit" or "implementation" sections before the first line (?). note that i mimicked the code on the SDL tutorial on http://www.freepascal-meets-sdl.net/ (chapter 3) where it is assumed i dont need what im being asked plus it is supposed to work with the command line compiler IDE (which im using)

since i only learned procedural pascal i dont know what an "interface" or "unit" or "implementation" is and as far as i know, the first line has always been "program program_name;"




program HelloSDL; // the program intends to show a simple image on the screen
USES SDL, CRT; // as said, the problem is the compiler asks for an "interface" and "unit" section before this line

VAR
screen,picture:pSDL_SURFACE;
source_rect,destination_rect:pSDL_RECT;

BEGIN
SDL_INIT(SDL_INIT_VIDEO);
screen:=SDL_SETVIDEOMODE(423,400,32,SDL_SWSURFACE) ;
IF screen=NIL THEN HALT;writeln('problem with the screen');

picture:=SDL_LOADBMP('C:\Documents and Settings\briss\Escritorio\hello_image.bmp');
IF picture=NIL THEN HALT;writeln('problem with the image');

NEW(source_rect);
source_rect^.x:=0;
source_rect^.y:=0;
source_rect^.w:=423;
source_rect^.h:=400;
NEW(destination_rect);
destination_rect^.x:=0;
destination_rect^.y:=0;
destination_rect^.w:=423;
destination_rect^.h:=400;

REPEAT
SDL_BLITSURFACE(picture,source_rect,screen,destina tion_rect);
SDL_FLIP(screen);
UNTIL keypressed;

SDL_FREESURFACE(picture);
SDL_FREESURFACE(screen);

DISPOSE(source_rect);
DISPOSE(destination_rect);

SDL_QUIT;
END.



well, it would be great if you help me make it work, i was planning on checking out allegro pascal tonight anyways so no big deal if i dont get any solution

User137
15-03-2012, 08:48 AM
Hmm, for console application that code looks valid. Normal pascal units have code structured like this:

unit MyUnit;
interface
uses ...
type
...
implementation
uses ...

code...

So for whatever reason, the compiler is treating your program as normal unit. Is it really the only file in the project, or how is it structured? What command did you use to compile it, or are you using Lazarus?

Super Vegeta
15-03-2012, 02:07 PM
For me the code compiles perfectly fine. As User137 already asked - are you using command line, or Lazarus? The other thing I'd suggest is taking a look whether the SDL .pas files are not bugged somehow, or if there aren't any additional files named HelloSDL laying around that the compiler might grab.

And btw, an advice for the SDL code - it can be easier if you use TSDL_Rects, and use the @ operator to create a pointer for the BlitSurface routine.

sacros
15-03-2012, 10:27 PM
For me the code compiles perfectly fine. As User137 already asked - are you using command line, or Lazarus? The other thing I'd suggest is taking a look whether the SDL .pas files are not bugged somehow, or if there aren't any additional files named HelloSDL laying around that the compiler might grab.

And btw, an advice for the SDL code - it can be easier if you use TSDL_Rects, and use the @ operator to create a pointer for the BlitSurface routine.

whoa! you solved my problem, guess what the name of my file was: SDL.pas; I didnt even know stuff worked like that, i installed the library via an installation wizard - so the compiler was assuming i was talking about the library .pas. Ill also look into which kind of sorcery is that @ operator and TSDL_Rects

now everything has turned color pink! not...new error, the code above now stops in the line:



screen:=SDL_SETVIDEOMODE(423,400,32,SDL_SWSURFACE) ;
IF screen=NIL THEN HALT;writeln('problem with the screen');

i also get the output "problem with the screen" so maybe there is a problem with the SDL_SETVIDEOMODE procedure? why nothing ever works :( at this rate im nevar gon build stuf

SilverWarior
16-03-2012, 12:58 AM
I asume you skiped first two chapters wich explain what is needed to be done to sucsesfully initialize SDL. SO i recomend to read them one by one, becouse only this way you will manage to get things going.
Probably the cuse of the problem in your case is that your program can't find path to sdl.dll dynamic library wich is requred for SDL to work at all. So make sure that sdl.dll is either inside your projects directory or somwhere on the system path, "C:\Windows\System32" for instance.

Super Vegeta
16-03-2012, 08:47 AM
Hah. Since you named the program file SDL.pas, when FPC encountered "uses SDL", it began to look for the SDL unit, and the first thing it saw was... SDL.pas. Which was not a unit, and that's why the compiler shouted about interface and implementation, which are unit parts.

Also, about the output - first thing, I guess you would want the writeln to be executed only if there actually is a problem and screen is NIL - begin end block? And putting it before halt. As for the SetVideoMode failing - I don't see a reason why would You need 32 bits for a display surface; type in either 24 or 0 (which will create a surface with a depth resembling the one currently used in the user's OS). You can eventually add the SDL_AnyFormat flag.

sacros
16-03-2012, 06:27 PM
Hah. Since you named the program file SDL.pas, when FPC encountered "uses SDL", it began to look for the SDL unit, and the first thing it saw was... SDL.pas. Which was not a unit, and that's why the compiler shouted about interface and implementation, which are unit parts.

Also, about the output - first thing, I guess you would want the writeln to be executed only if there actually is a problem and screen is NIL - begin end block? And putting it before halt. As for the SetVideoMode failing - I don't see a reason why would You need 32 bits for a display surface; type in either 24 or 0 (which will create a surface with a depth resembling the one currently used in the user's OS). You can eventually add the SDL_AnyFormat flag.

whoaaa! and so you´ve solved my problem a second time, what are you, god or something?

I didnt notice the writeln was outside the if block since it didnt have the begin-end so since the writeln showed then the issue was actually with the loading of the image!

and then i remembered the image being used was at some point a jpg which i changed to .bmp simply by renaming the extension xD meaning internally was still formatted as a jpg right?

SO IT WORKS NOW, IT WORKS, OH GOD IT WORKS IT WORKS IT WORKS ama gon build gaems....im just worried about how hard i tend to **** stuff up...i mean, so simple code yet so many stupid mistakes, i wonder if ill ever get somewhere...oh well, theres lots of fail ahead of me - Oh by the way, will the computer that wants to execute the program i make need the SDL library too?

thank you so much vegeta, i totally owe you two

Ñuño Martínez
19-03-2012, 10:57 PM
id love to know what you mean by "there is pixel handling issues in windows", is it like it has problems working with single pixels or is it something with raster based stuff in general? The OpenGL raster does work, I mean you can use all "gl..." procedures and it will work, but Allegro.pas 5 "software raster" (i.e. the "al_..." procedures) does fail if you try to draw pixels (al_draw_pixel) or text (al_draw_text, etc.) but it doesn't fail if you draw lines (al_draw_line).

It isn't a big problem because you can do all graphic drawing using OpenGL but then you can't create textures or modify them on the fly (you can still load them from disk, anyway). On Linux it works without problem.

Allegro.pas 4 does work both Windows and Linux without problem, but it doesn't allows OpenGL. :(