Archived

This topic is now archived and is closed to further replies.

Delphi and OpenGL

This topic is 5336 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

Lets say if have this txt file: NumberOfBoxes = "2" Box1: Texture="texture1.bmp" "1.1,0.3,3.5: 2.3,3.9,2.3: 1.3,5.2,4.1: 4.5,2.1,4.3:" EndBox1; <- Just some random coords. Box2: Texture="texture2.bmp" "4.1,0.3,3.5: 2.3,3.9,2.3: 1.3,2.2,4.4: 4.5,2.1,2.3:" EndBox2; EndNumberOfBoxes; Now I want to code a Delphi-program to load this file (lets say it''s called boxes.txt) and then draw the number of boxes represent by NumberOfBoxes = "2" and by the correct coordinates and then insert the correct texture.

Share this post


Link to post
Share on other sites
quote:
Original post by dcgeek Now I want to code a Delphi-program to load this file (lets say it''s called boxes.txt) and then draw the number of boxes represent by NumberOfBoxes = "2" and by the correct coordinates and then insert the correct texture.

Well, you have my approval to do this, go ahead and have fun! And may you ever need help, feel free to post in this forum, off course!

Share this post


Link to post
Share on other sites
Which specific part of it, or just all of it? For the file handling part, have a look at my files tutorial. In this case you want to declare a TextFile and store your files as text, not binary (much simpler). Use AssignFile, Reset, Read/ReadLn and CloseFile to read your data from file.

The next step is to have an intermediate format in your program into which you''ll read the stuff. You can use records in Delphi (like structs in C) for this.

At some point you''ll have to initialise OpenGL. The simplest method would be to go to Nehe. There are a few Delphi projects that get the nasty initialisation out of the way. You can have a look at "NeheGL Delphi" or "NeheGL Delphi OOP" on the left sidebar of the main page or you can take one of the tutorials and rip out unnecessary stuff. Basically, you just want a simple window/fullscreen initialisation and shutdown. Don''t fret about the stuff you''ve ignored because you can look at it later.

A quick note: Tom Nuydens over at Delphi3d has the best OpenGL headers -- they''re definitely much more complete than the standard ones that ship with Delphi. It might be worth your while to use ''em. You can also google for Mike Lischke''s Opengl12.pas, which is good too.

So -- you declare records for your info (declaring types for vectors, faces, or whatever else is relevant). Next, declare variables of the previous record types. You open the file and read the information from the file into your records. Once you''ve done this, you''ll need to load up the textures from file -- NeHe has tutorials on this so have a look at the Delphi conversion of them. However, NeHe may use glAux to load in the bitmaps, which sucks.

You might think about creating Display Lists for your boxes. NeHe covers this is lesson 12.

Once you''re drawing it, you start of by clearing the background (equivalent of a fillrect) and the z buffer. You can do this using glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); (or something like that, I forget exactly). Next up, you want to reset the view -- use glMatrixMode(GL_MODELVIEW) and glLoadIdentity to load the identity matrix. Next, you display the boxes using any number of different methods (e.g. glCallLists is you''ve used display lists, glBegin/glEnd if you want, or vertex arrays, or...). If you''re using Display lists then it''s just a case of glTranslatef/glRotatef/glPushMatrix/glPopMatrix as appropriate.

Check out Nehe''s lesson 12 -- it deals with loading in boxes into display lists and displaying them.

Share this post


Link to post
Share on other sites
afaik it should be no problem to import a MSVC 6-project into your dev-cpp development environment (at least i never had problems with that ... there''s even an import-function provided by the ide [which you''ll have, i guess]).

Indeterminatus

--si tacuisses, philosophus mansisses--

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What''s wrong with you? Just do it! Why would someone write this, when you''re either perfectly capabale of spending 15 minutes to do it, or obviously in need of some practice?

Share this post


Link to post
Share on other sites
quote:
Original post by dcgeek
Okay... will someone in here make the whole program for me? Please


Yes I''ll do it. Give me your email address I''ll send you my rates.

Share this post


Link to post
Share on other sites
I need to do it in practice... I just can''t learn anything before I see how it works in practice, and THEN I can read all the theory.


petewood - thank you, my email is dcgeek@mail-online.dk

Share this post


Link to post
Share on other sites
Okay, from our private correspondence it looks as though what you want to learn is how to parse the text file and convert that into OpenGL commands. You know enough OpenGL to be able to take care of that end of things.

What is the file format? Is it something you've created yourself or does it come from somewhere else. Is this just a little example or is it part of a larger piece of work? Are there only boxes in the file (because we could just hard code it all) or do you need something more extensible? Is it possible to change the file format or is it important to you that we use the one you have?

Do you know what a parser is?

Does anyone know some useful links?

[edited by - petewood on May 6, 2003 11:27:07 AM]

Share this post


Link to post
Share on other sites
It doesn''t matter what fileformat... It could be a .txt, .dat or whatever you wanna call it.

I have not started on it, and it is not a part of a larger piece of work.

If possible, then it would be nice if I can specifi in the script-file if the object should be a box, triangle or circle.

I think I know what a parser is, but i''m not sure.
Isn''t it something like a program that reads a file like this:

abc="hello world"=abc

and then reads everything between abc=" and "=abc ?

Share this post


Link to post
Share on other sites