Thanks for your reply, I've tried everything so far with no luck. I was thinking that it might be possibily due to the placement of my code? Since everything gets compiled in a linear fashion and the load parameter is near the end of the file. May be it's not locating the file because it isn't being loaded at the right time.
(Update: I was about to upload my code into I found out that somehow all of my .cpp files have been overwritten by the same texture loader I built a while ago, which has now angered me. I will try re-writting everything and hopefully may I might figure out my error along the way this time. If not I shall upload the code once I'm finished, Sorry about this and thank you everyone!)
Show differencesHistory of post edits
#1Coro
Posted 10 September 2012 - 01:23 PM
Thanks for your reply, I've tried everything so far with no luck. I was thinking that it might be possibily due to the placement of my code? Since everything gets compiled in a linear fashion and the load parameter is near the end of the file. May be it's not locating the file because it isn't being loaded at the right time. Here's all of my code:
/*===================
= Include =
===================*/
#include <SDL/SDL.h> //SDL API, used for Rendering with Open GL as well as controlling I/O
#include <SDL/SDL_image.h>
#include <Windows.h>
#include "GLee.h"
#include <GL/gl.h> // Open GL File
#include <GL/glu.h> // Open GL Utility File
#include <iostream>
#include <vector>
/*===================
= Declaration =
===================*/
float angle = 0.0;
const int triangle=1;
unsigned int image;
/*===================
= Initialisation =
===================*/
unsigned int loadTexture(const char*filename)
{
SDL_Surface* image=IMG_Load(filename);
if(image==NULL)
{
std::cout << "Image was not found" << std::endl; return -1;
}
SDL_PixelFormat form=
{NULL, 32, 4, 0,0,0,0,0,0,0,0,0xff000000,0x00ff0000,0x0000ff00,0x000000ff,0,255};
SDL_Surface* image02=SDL_ConvertSurface(image,&form,SDL_SWSURFACE);
if(image02==NULL)
{
std::cout << "Error occurred whilst trying to load image to memory" << std::endl;
return -1;
}
unsigned int id;
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image->w,image->h,0,GL_RGBA,GL_UNSIGNED_INT_8_8_8_8,image->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
SDL_FreeSurface(image);
SDL_FreeSurface(image02);
return id;
}
void init()
{
glClearColor(0.0,0.0,0.0,1.0);
glMatrixMode(GL_PROJECTION); // Set Projection Matrix mode
glLoadIdentity(); // Resets default mode
gluPerspective(45,640.0/480.0,1.0,500.0); // Creates virtual enviromental perspective
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
image=loadTexture("opengl_icon.bmp");
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glRotatef(angle, 1.0, 1.0, 1.0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,image);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0);
glVertex3f(-2.0, 2.0, 0.0); // Bottom Right
glTexCoord2f(0.0, 0.0);
glVertex3f(-2.0, -2.0, 0.0); //Bottom Left
glTexCoord2f(1.0, 1.0);
glVertex3f(2.0, -2.0, 0.0); // Top Right
glTexCoord2f(1.0, 0.0);
glVertex3f(2.0, 2.0, 0.0); // Top Left
glEnd();
}
int main(int argc, char** argv) //argc holds the number of arguments, argv is the list of arguements
{
SDL_Init(SDL_INIT_EVERYTHING); //Initialises everything within the SDL API
SDL_Surface* screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE|SDL_OPENGL); //Sets up GL with screen dimensions
bool running = true;
Uint32 start; //Unsigned32bit integer
SDL_Event event;
init();
const int FPS=30;
while(running)
{
start=SDL_GetTicks(); //start = FPS
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
running = false;
break;
}
}
display();
SDL_GL_SwapBuffers();
angle +=1.0;
if(angle>360)
angle-=360;
if(1000/FPS>SDL_GetTicks()-start)
SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
/*If FPS rate is lower then 30FPS in one cycle of loop then
regulate the FPS to prevent freeze */
}
SDL_Quit();
return 0;
}