Delphi and OpenGL

Started by
14 comments, last by dcgeek 20 years, 11 months ago
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.
Advertisement
It''s also ok in C/C++
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!

Newbie programmers think programming is hard.Amature programmers think programming is easy.Professional programmers know programming is hard.
I am asking for help about HOW to do it!
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.
Can I get the full source-code?
(if for C++, get it to work with Dev-C++, i don''t have MS Visual C++).
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--
Indeterminatus--si tacuisses, philosophus mansisses--
Okay... will someone in here make the whole program for me? Please
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?
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.

This topic is closed to new replies.

Advertisement