I have recently started a project with SDL involving 2d graphics. I am fairly new to graphics programming, but I feel that I have a good grip on the subject. I was wondering if anyone could answer a few questions for me though:
first of all, I have a recurring problem with loading texture. I have my texture load function set up like this:
GLuint loadTexture (const std::string&fileName) //Load texture function
SDL_Surface *image = IMG_Load(fileName.c_str() );
glBindTexture(GL_TEXTURE_2D, object); //Bind to an object
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->w, image->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
I followed a tutorial to build this function, but I do not know what most of it does. If anyone could explain it to me in detail I would appreciate it. My error, however, involves execution of my program as a whole. Every time I call this function, I get an access violation error if the dimensions of my .PNG file are not a power of 2, and are not 128 pixels or more for each dimension. This is a problem, because my objects that I am binding the textures to are not above 128 pixels each, and I always have a horrible skewing effect. I tried resizing the glTexCoord for my object, but the skewing remains. Does anyone know a reliable and efficient workaround or fix for this?
My next issue is with collision. I have a very shoddy collision detection function that I want to replace with something better and more comprehensive, but I don't know where to start. If anyone could direct me to a good tutorial on collision that would be all I would need for now.
Finally, I was wondering if anyone could show me how to move the camera during movement, like a side-scrolling function, but from a top down perspective. I have no idea where to start in that regard, and a detailed example would be wonderful.
If anyone has the time to answer at least one my questions, I would appreciate it greatly.