PDA

View Full Version : Really need help



Nial
03-30-2002, 12:33 PM
I've been trying for 3 weeks now and cant get my code to work!! Could someone give me a *fully* working .c file of code which gets opengl to load a bmp (im making an RPG engine) and then places the RPG all over the screen.. in other languages all you have to do is load the BMP into memory and then tell it to plot at 0,0 or 40,40 etc. and the image will be placed there.. can someone give me all the code I need to do this. Pointing me to a tutorial wont help as I've read hundreds!

ThinIce
03-30-2002, 01:16 PM
Dude, if you've read hundreds, non the less at least 4 tutorials on loading a .BMP, you'd definately know what to do. I suggest you slow down, and reread a few. I think nehe.gamedev.net has what you need. We can't write you program for you, you need to learn, if one gets spoon fed code, and doesn't learn, what good is it?

Old GLman
03-30-2002, 01:17 PM
Hi. Just try posting your code. Allot of the people in here could spot what your doing wrong pretty quick. OpenGL doesnt load bitmaps, you have do to that yourself. Fully working code for that is on nehe.gamedev.net. You can do everything you want to do in C. All you have to do is like you said, load it into memory, map it to a quad, and place it on the screen. Im sorry, but if you have been trying for 3 weeks just to do this, with all the information available, then you have not been trying very hard. There is no short cut. Essentially your better of learning it yourself.

Old GLman

Nial
03-30-2002, 01:45 PM
My code:

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,-5.0f);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glEnd();

xrot+=0.3f;
yrot+=0.2f;
zrot+=0.4f;
return TRUE; // Keep Going
}

Its not all of it but its my drawing code.. this works.. it loads the 256x256 nehe texture and displays it.. it was originally coded to spin a cube but i stopped the cube from spinning and removed its faces except for one square face.. which displays my texture..

But even when I make an image that is 50x50 it resizes it to 256x256 and displays it like that!

I need to know how to make the images display at their actual size and also i dont understand how to make the image plot itself at 0,0 or 40,40! Please help.

Old GLman
03-30-2002, 05:15 PM
Hi. That code looks like it is from NeHe tutorial #6. Somewhere at the beginning of the tutorial he says:

"Before I start explaining the code there are a few VERY important things you need to know about the images you plan to use as textures. The image height and width MUST be a power of 2. The width and height must be at least 64 pixels, and for compatability reasons, shouldn't be more than 256 pixels. If the image you want to use is not 64, 128 or 256 pixels on the width or height, resize it in an art program. There are ways around this limitation, but for now we'll just stick to standard texture sizes."

To display a portion of a specified image you will want glTexSubImage2d(). I believe NeHe lesson 30 has information on that.
Feel free to ask more questions if you have them.

Old GLman

nexusone
03-30-2002, 05:57 PM
There are a few RPG's out there with opengl as the frame work.

Since you have been on the nehe, you should look at the zelda project he is working on. If you don't know "Zelda" is a RPG style game.


Your image size on the screen is based on the location and size of the object you place it on. So no matter what you do to change the image size if will always be the made to fit the object. (In your case the qaud).

Also you need to use a base 8 number, try 64 instead of 50.

Also if you had a understanding of how a tile based program works even if it is not a opengl base program would be helpful to you.
look at www.gamedev.net (http://www.gamedev.net) for info on tile based games. (What most RPG's are.).


Originally posted by Nial:
My code:

int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,-5.0f);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glEnd();

xrot+=0.3f;
yrot+=0.2f;
zrot+=0.4f;
return TRUE; // Keep Going
}

Its not all of it but its my drawing code.. this works.. it loads the 256x256 nehe texture and displays it.. it was originally coded to spin a cube but i stopped the cube from spinning and removed its faces except for one square face.. which displays my texture..

But even when I make an image that is 50x50 it resizes it to 256x256 and displays it like that!

I need to know how to make the images display at their actual size and also i dont understand how to make the image plot itself at 0,0 or 40,40! Please help.

Nial
03-31-2002, 12:07 AM
I've coded numerous RPG engines, just not in c++.. secondly although openGL is powerful it seems too confusing when trying to do a simple task!!

nexusone
03-31-2002, 05:42 AM
What makes C so powerful is the fact the most other languages have been built from it. It is because you do not have a good understanding of the system, but once you learn how to program with it, you will see the advantages to it.

First to help make programming simpler librarys of function built with the base function have been made like glu, glut, fmod(fmod is not a opengl library, but was made so you did not have to write the primitive code to made sound).

Here is a link to an C and opengl base RPG project. http://terrarpg.sourceforge.net/


First you need to get out of your mind pixel size, one gl unit is not one pixel it could be any number of pixels. Unlike what you have been programming under which works in pixels, you can not work that way in opengl.

You understand how tiling works in a RPG, here is how you would do it in openGL.

First you would have a map, just like in any tile program. Telling what tile is to be place where.

Say you want a 64 x 64 tile sized world, each tile would hold an image 64 x 64 pixels in size.

Let's say your window view would be 8 X 8 tiles, so you would set your opengl view 8 gl unit tall and wide.

You would load all of you tile textures into memory.

When drawing you would draw one texture per quad, the quad size is 1 X 1.
Use glTranlate to move your quads position.
first row tile = 0,0... end first row tile = 0,64
Last row tile = 63,0... end last row tile = 63,63.


example:
**************** *= 1 X 1 quad
****************
****************
*********+++**** += current area being viewed
*********+++****
****************

By just moving the view area, you get the scrolling of the map.



Originally posted by Nial:
I've coded numerous RPG engines, just not in c++.. secondly although openGL is powerful it seems too confusing when trying to do a simple task!!

john
04-01-2002, 05:50 AM
C is not a powerful language. it's not expressive and it's not wonderfully structured. it's only claim to fame is that almost everything works with it.

nexusone
04-01-2002, 07:09 AM
If a C program is not structured well it is due to the programmer and not the fault of the language.

Programming is like art, some artiest use oil paint others like ink. The same with programmers, each his own language of expression!

http://www.opengl.org/discussion_boards/ubb/smile.gif

Opinions are like *******s, everyone has got one!


Originally posted by john:
C is not a powerful language. it's not expressive and it's not wonderfully structured. it's only claim to fame is that almost everything works with it.

john
04-01-2002, 03:40 PM
C is widely recognised as having bad structure. yes, i agree that a programmer has to be good to deal with bad structure, but that isn't the same thing.

- the scope rules are shockingly inadequate
- it has no typing
- it can't express high level abstraction like parallelism, concurrency, synchorinsation, etc.
- and so on.

cheers,
John

nexusone
04-01-2002, 06:44 PM
The only programming lanuage that comes close to that is the one used by the time lords of Gallifrey..... And you could alter time and space with it!!!!!

http://www.opengl.org/discussion_boards/ubb/smile.gif


Originally posted by john:
C is widely recognised as having bad structure. yes, i agree that a programmer has to be good to deal with bad structure, but that isn't the same thing.

- the scope rules are shockingly inadequate
- it has no typing
- it can't express high level abstraction like parallelism, concurrency, synchorinsation, etc.
- and so on.

cheers,
John

john
04-01-2002, 09:03 PM
time lords?
as in, dr who?

was the tardis programmed with it?

nexusone
04-02-2002, 05:36 AM
Yes, I was joking with you old boy....
When you starting talking about abstract features in a programming lanuage, the Tardis OS came into mind....

http://www.opengl.org/discussion_boards/ubb/smile.gif

That reminds me of the set of 3D Dr Who objects I have been working on.....I want to do a 3D Dr. Who game(any body else interested?)



Originally posted by john:
time lords?
as in, dr who?

was the tardis programmed with it?

Furrage
04-03-2002, 12:33 PM
For those who have forgotton... Or did not know...

C is a language somewhere between 3GL (Third Generation Language) and Assembly. Things like Pascal, and Visual Basic are 3GLs or higher. As you progress up the chain from assembly to 4GLs or whatever they have now, coding gets simpler, more logical, easier and less time consuming. However, your ability to tweak code and optimise becomes more limited as you progress up the chain. The languages also tend to make more bloated code as you go up the chain.

So where does that leave C? In the best of 2 worlds if you're willing to learn it. You get flexibility and power, the ability to handle low level stuff, to optimise and stuff, and raw speed that only assembly can beat. You also get it at a level high enough to not seem (too) cryptic, like assembly. These features make C so compelling that other programming languages are built using C.

However, while this was good then, 2+ GHz processors and PC/800 Memory means that power may not be such an issue any more. What matters more is development time, and it is argued that higher level languages require less development time to build something than C would. Also while you can tweak C its likely that another language has had their functions tweaked enough to perform better than equivalent C code done by an average programmer.

In the long run, its a matter of preference. Power vs. Ease of Use, Programme Speed vs. Development Time, Flexibility vs. Useability, etc, etc. Well you get the picture.