Hi,
I'm having a few issues with my application, and have a few queries. If you can help with any of them it would be greatly appreciated (These were all problems I gathered from not being able to find a solution on google).
I will list them here tl;dr version - maybe you can see what you might know:
1. Mipmapping isn't working
2. blending textures/quads to make a smooth transition between separate textures - not sure how to approach this
3. Being able layer 2 textures, or one texture with transparent parts showing a unique color (need multiple possible colors for a single object)
4. Importing Maya/3dsMax animation - More looking for guidance - will not attempt this in the next few months, but maybe after.
(Not OpenGL related, but I don't want to make too many topics - let me know if I should put these in a seperate thread)
5. How to determine if a chunk is in camera view - i.e. what to not render.
6. RTS drag selection - I know how to do one selection (with unit represented as a sphere and raysphering with the mouse), but how to drag a box like in all rts games, and have all units within that selected? I'm sure the math is really simple but I can't think of it.
Ok here are the questions in full:
__________________________________________________________________
1. Firstly, when I load a texture with mipmapping it just gives me a plain white texture (with value of -1). If I don't use mipmapping (enter mipmap as false), the texture renders fine, but looks like crap a long distance away.
My code is here:
int GRAPHICS::LoadTexture(const char *filename, bool mipmap, bool repeat)
{
glEnable(GL_TEXTURE_2D);
unsigned int id;
glGenTextures(1, &id);
SDL_Surface* img = IMG_Load(filename);
if (img == NULL)
{
OutputDebugString("\"");
OutputDebugString(filename);
OutputDebugString("\" failed to load.\n");
return -1;
}
SDL_PixelFormat form = {NULL, 32, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 0, 255};
SDL_Surface *img2 = SDL_ConvertSurface(img, &form, SDL_SWSURFACE);
if (img2 == NULL)
{
OutputDebugString("\"");
OutputDebugString(filename);
OutputDebugString("\" failed to load. img2 == -1\n");
return -1;
}
glBindTexture(GL_TEXTURE_2D, id);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
// Mipmapping
if (mipmap)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, img2->w, img2->h, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img2->pixels);
else
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,img2->w,img2->h,0,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8,img2->pixels);
// Min Filter
if (mipmap)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
else
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
// Repeat
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, repeat ? GL_REPEAT : GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, repeat ? GL_REPEAT : GL_CLAMP );
SDL_FreeSurface(img);
SDL_FreeSurface(img2);
return id;
}
Here's my Init function if you want to know that:
void GRAPHICS::Init(int width, int height, bool fullscreen)
{
SDL_Init(SDL_INIT_EVERYTHING);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Refresh(width, height, 45.0f, fullscreen);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glLoadIdentity();
}
And the refresh function:
void GRAPHICS::Refresh(int width, int height, float fov, bool fullscreen)
{
if (fullscreen)
SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_OPENGL | SDL_FULLSCREEN);
else
SDL_SetVideoMode(width, height, 32, SDL_SWSURFACE | SDL_OPENGL);
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov, ((float)width*2) / (float)height, 0.1, 500.0);
}
2. Secondly, I need to have my textures blend together. I can't really describe it with words so I will post an image:
Left is my game so far, you can see the tiles don't blend, on the right is empire earth, the kind of thing I'm wanting to do. It's early enough that I can restructure my tile system. but I am not wanting to make a unique texture for blending every combination of tiles (coz there's a tonne if I want many variants of the tiles)
3. Thirdly, I want part of a texture to change color. I'm wanting to make an RTS - meaning many players can use the same units, but each unit needs to have part of their texture be a different colour. I do not know how to do this. I want to only need to load each object once. Look at right image above, see the blue on the little man, you can make this color anything in that game. That is what I am wanting.
What I was thinking with this is that If I could somehow just apply first a color (like blue or red), and on top of that apply the normal texture, and that texture's transparent parts will show through the color underneath. (For example, I could do glColor3f(1.0f, 0.0f, 0.0f) then glCallList of the object)
4. Fourthly, this is not so urgent, as I don't think I will implement this anytime soon, but is there a way to export animation the same way I export obj files? obj files are so good because they display each vertex, and I just read this data in. That's how I got the trees and the white dude in my scene, but I can't bring in any animation unless I export each frame as an object - something I'm not wanting to do.
I use Maya/3dsMax, any guidance is appreciated.
5. In my game, I have the world made of chunks, and each chunk contains 4x4 reference to tiles(I think it's better than just tiles on their own, maybe not feel free to give your opinion - I'm sure they might be helpful) - Is there a way to determine if one of these areas is not in view? At the moment I just draw everything, even if I can only see a few tiles.
6. RTS drag selection - Most info given in tl;dr - I already have a way to get opengl positions from the mouse (close and far to cast ray in right direction), I'm just not sure of how to draw a box (which would be 2D for the player) and have it know everything inside. I mean, the camera can rotate, then might start dragging from a spot, and drag across many screens, making the start point actually off screen. So many problems, not sure how to solve.
Any help/or suggestions with any of these things will be greatly appreciated. I will tend to this thread when I'm not working. I am not a good programmer, so some of these might be really obvious, and I'm sorry if that is so.