Sign in to follow this  

Few questions (okay, in fact: lots of questions)

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

Hi, I have got several question, but I do not like to open mutiple threads, so I will put everything together ;) 1. About the jpeglib. Has someone used it right now? I included all the needed headers and added the libjpeg.lib to my project, but the linker kepps telling me about the undefined references to the functions. Did I miss something? 2. The background again. My project mate keeps nagging about the big textures he has to use when taking skyspheres. He will not take skyboxes, as he realistic background with nebulas and so on. His idol is a game called "X-Tension", where the programmers used little textures (less than 256x256) to fill almost the whole sphere in good quality. He thinks there must be a trick, but I do not think that something like this is possible if the whole texture is mapped on the sphere. Perhaps you have got an idea? 3. Is there any way to control the "repetition rate" (I hope you know what I mean) of the monitor via OpenGL? In other programs there is sometimes the option to set the repetition rate to 60Hz or higher... but I did not hear of that in connection with OpenGL. Perhaps you can give me a hint? 4. That was already all =) Thanks in advance, Marco *the guy who doesn't stop asking ;)*

Share this post


Link to post
Share on other sites
1. don't use jpegs as textures, they are bad, use libpng or openIL.

2. a skybox has less distortion than a skysphere and thus needs smaller textures to acheve the same result.
If it's only a starfield it's possible to use the same texture for all faces.
A good skybox is something that enhances the game by a lot, it is totaly justified to use 512x512 textures.

3. the refresh rate is set either by the driver if you use windowed mode, if you use fullscreen mode i think the refresh rate can be set manualy.
If not, it defaults to the previous refresh rate.
but it isn't done with openGL, it is done in windows.

Share this post


Link to post
Share on other sites
Quote:
Original post by lc_overlord
1. don't use jpegs as textures, they are bad,

Jpegs *can* be used as diffuse textures if you use low compression/high quality. But it's true that they are really bad for normalmaps.

Quote:
Original post by lc_overlord
2. a skybox has less distortion than a skysphere and thus needs smaller textures to acheve the same result.

It totaly depends on mapping/coordinats. You can map dome in a way noone will be abe to tell if its a dome or a box.

Quote:
Original post by Marco H
Is there any way to control the "repetition rate" (I hope you know what I mean) of the monitor via OpenGL? In other programs there is sometimes the option to set the repetition rate to 60Hz or higher... but I did not hear of that in connection with OpenGL.
Perhaps you can give me a hint?

Its refresh rate. Take a look at ChangeDisplaySettings.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by _DarkWIng_
It totaly depends on mapping/coordinats. You can map dome in a way noone will be abe to tell if its a dome or a box.


True, but a skybox still has a more even distibution of texels and less texture distortion than any sphere or dome projection method.
Not to mention it's a lot more easier than doing some custom spherical projection.

the only thing that would be better would be to use some type of spherical texture format(it's on my list of things to do), but sadly it's not supported by any harware, i wish it was.

Share this post


Link to post
Share on other sites
Quote:
Original post by lc_overlord
1. don't use jpegs as textures, they are bad, use libpng or openIL.

I will give it a look (in fact, my project mate wanted jpeg, because of the new jpeg2000 standard, which is not a bad choice in my opinion).
But as I almost got it - why not use it? Do you have some hints to solve my linker-problem?

2. Skyboxes are fine, but what if I want to place a huge nebula in my game? Are the the edges visible?
As I said, my mate keeps nagging about the little textures he had to use in connection with domes in another game (he modded it very intensively) to achieve good quality results. Is something like that possible if the texture is mapped onto the whole dome?

Share this post


Link to post
Share on other sites
Edges will not be visible if you do it correctly.
alternatively you could render the nebula in there separatly on top of the skybox.

IT's all up to how mutch detail you want in the game.

Share this post


Link to post
Share on other sites
Details should be that far as others wish it. I designed my game to be very friendly to modders, as they can create new sectors and objects (stations, ships, nebulas etc.) without any problems.

So, my program reads text-files, which include the neccessary data. The skybox or skydome is only a 3d-model, so one can decide what to use. Normal placed objects and static objects (you can never reach them, like the moon in the real world as you are driving in your car ;) ) are selectable, billboards will be added soon.

But in fact that is not my problem ;-) The question was, if there could be a little texture mapped on a big sphere without losing its quality. I suspect this option does not exist, as the texture will always be stretched, right?

Share this post


Link to post
Share on other sites
Hello,

I do not want to start a new thread, so I use this one, as the title still fits :)

I finished implementing the jpeg-loader and it seems to work, but somehow the images are morrored horizontally. How could I avoid or change this? Swap the image data somehow perhaps?

Share this post


Link to post
Share on other sites
You could flip it when loading or change mapping coordinats.

Its flipped compated to what? TGAs? If that is so then I thing the TGAs loader is wrong since TGAs are somethimes saved in flipped way. Theck format specification. There is a bit in header that tells if you need to flip it or not.

Share this post


Link to post
Share on other sites
They are flipped compared to TGA and BMPm so I think the mistake is to be found at the JPEG loading.
I can not change the loading routines, as they are delivered in a library, but I can try to swap the bytes in order to get the desired look, right?

Share this post


Link to post
Share on other sites
Well.

Id guess the jpg loading is correct as it is since both TGA and BMP most commonly is saved upside down.

At least Photoshop, Paint Shop Pro, Gimp and Windows Paint all save them upside down.

So most likely your texcoords so far is upside down to "fix" the fact all the TGA's and BMP are loaded upside down.

Share this post


Link to post
Share on other sites
BMPs are saved upside down? I did not know... but if they are saved in that way, they should be mirrored horizontally and vertically, not only horizontally, or not?

Share this post


Link to post
Share on other sites
Thanks a lot, I did it now :)

But another question - lc_overlord said I should use PNGs as images. Right now I tried to google some infomation or a kind of tutorial about that, bu I had no success.

Do you know where I can find a tutorial or something like that to show how to load PNGs? I do not want to use SDL oder OpenIL, if not neccessary...

Thanks in advance,
Marco

Share this post


Link to post
Share on other sites
I just got a couple of sites out of google, but I have to warn you that PNG loading doesn't seem so easy to me (at least judging by the lenght of these pages)

http://netghost.narod.ru/gff/graphics/summary/png.htm
http://www.corion.net/cgi-bin/wiki.cgi/display/Format:PNG

Both these links (or any other like these) give you information about how data is stored in a PNG file.
I'm not really sure this is what you're looking for.

Share this post


Link to post
Share on other sites
I have been looking for some examples, but the links are also good, thanks :)

And I have another question: if I have a structure like that:
struct something
{
int static_one;
int * dynamic_one;
};


and I allocate it like that:
//...
something * anything = new something;
anything->dynamic_one = new int[10];
//...


After using the structure I do not have any use for it, so I want to delete it. Do I have to delete the "dynamic_one"-array before deleting the whole structure or may it even end in an access violation?

(as always) Thanks in advance,
Marco (the guy who loves this forum)

Share this post


Link to post
Share on other sites
Quote:
Original post by Marco H
After using the structure I do not have any use for it, so I want to delete it. Do I have to delete the "dynamic_one"-array before deleting the whole structure or may it even end in an access violation?

You have to delete "dynamic_one" before deleting "something". It won't cause access violiation but it will be a memory leak. My sugestion would be to use destructor for this.

class something {
int static_one;
int * dynamic_one;
something() {
dynamic_one = NULL;
}
~something() {
if ( dynamic_one != NULL ) delete[] dynamic_one;
}
// other methods...
};

Share this post


Link to post
Share on other sites
Okay, thanks, it is a nice tip :)

In fact I am trying to find a strange in my program. I found out, that it crashes on calls like "num_vertices = new word;" or things like that (only normal allocations). So I think that I have a memory leak somewhere... or what do you think?

One more thing: declarations like "char anyChar[32];" do not have to be deleted, or?
(You see, I am looking intensivly for an error...)

Share this post


Link to post
Share on other sites
A memory leak is when you allocate some memory using the new operator, and forget to delete it again.

Consider the following code:

char *string = new char[32];


This will require that you also delete:

delete[] string;


the [] is used because it was allocated as an array.

Now, if you just declare the array, like so:
char string[32];

there's no need to delete it, because you haven't actually used the new operator.

Share this post


Link to post
Share on other sites
Every call to operator new must be matched by exactly one call to operator delete. Every call to operator new[] must be matched by exactly one call to operator delete[]. Every call to malloc should be matched by exactly one call to free. It is generally good advise to avoid using malloc in C++ because this saves you the worry of trying to distinguish between what you should delete([]) and what you should free.

Quote:
Original post by _DarkWIng_
~something() {
if ( dynamic_one != NULL ) delete[] dynamic_one;
}


No need to test for nullness. The C++ standard guarantees that deleting a null pointer is safe, so the test is redundant.

Enigma

Share this post


Link to post
Share on other sites
Thanks, that helped me a lot.

But now: another question :)
My code to load a texture looks like that:

GLubyte * imageData;  //store the raw data

GLuint texID; //texture name
texID = loadAnyImageFormat(imageData, file_name); //returns the name and fills the image data

glGenTextures(1,texID);
glBindTexture(GL_TEXTURE_2D,texID);

gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB8,width,height,type,GL_UNSIGNED_BYTE,imageData); //build the texture



Everything is okay, nothing to complain. But now I want to delete this texture and there is something that is not totally clear to me.
If I call "glDeleteTextures(1,&texID);", is the "imageData" automatically deleted or do I have to do this myself?

Share this post


Link to post
Share on other sites
Quote:
Original post by Enigma
No need to test for nullness. The C++ standard guarantees that deleting a null pointer is safe, so the test is redundant.

Thanks for correction. I'm always forgetting this.

Quote:
Original post by Marco H
If I call "glDeleteTextures(1,&texID);", is the "imageData" automatically deleted or do I have to do this myself?

You have to delete imageData yourself. You don't have to wait until deleting texture. You can get rid of it right after uploading it to opengl (after gluBuild2DMipmaps).

Share this post


Link to post
Share on other sites
You are right! Thanks for the tip, it is really good to know :)

Seems like I found my mistake an now my program does not crash even if I load a level a hundred times :)

Thanks, thanks and thanks again :-)

Share this post


Link to post
Share on other sites
One more question... is it allowed to post information for my project here in this forum? It would be a kind of advertising, but perhaps it could help me to improve it a bit :-)

Share this post


Link to post
Share on other sites

This topic is 4725 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this