I had made a simple 3d engine, about a month or two before the big Graphics update for SFML2, and just recently revived it, and started working on it, when I had a problem with the openGL side..
Two variables changed since, SFML and my computer.
Basically, here is the issue.
Textures.
I know i'm supposed to call glBindTexture BEFORE glBegin, not Between glBegin/glEnd
However, if I DON'T put it in between, textures are white.
If I DO put it in between, they show...badly.
it didn't do this before I updated my computer/sfml.
is there something wrong with my code?
Setting up the window...
int main(){
sf::ContextSettings Settings;
Settings.depthBits = 24; // Request a 24 bits depth buffer
Settings.stencilBits = 8; // Request a 8 bits stencil buffer
Settings.antialiasingLevel = 2; // Request 2 levels of antialiasing
sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "PeriLib", sf::Style::Close, Settings);
Base_Controller Engine;
Engine.SetWindow(&Window);
return Engine.Run();
}
my texture variables (temporary, was testing for the problem)
GLuint skyboxfront;
GLuint skyboxback;
GLuint skyboxtop;
GLuint skyboxbottom;
GLuint skyboxright;
GLuint skyboxleft;
Loading Textures
GLuint Texture1; // UNIQUE texture number, every texture is last texturenum + 1! e.x Texture2 = 1, Texture3 = 2
sf::Image Image;
Image.loadFromFile(Path);
glGenTextures(1, &Texture1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Image.getSize().x, Image.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, Image.getPixelsPtr());
myUniqueCounter++;
myTextures.push_back(Texture1); // Add texture to vector!
std::cout << "New texture added!" << " : " << myTextures.size() - 1 << std::endl;
return Texture1;
Storing Textures
skyboxfront = Graphics.AddTexture("skybox_front.png");
skyboxleft = Graphics.AddTexture("skybox_left.png");
skyboxback = Graphics.AddTexture("skybox_back.png");
skyboxright = Graphics.AddTexture("skybox_right.png");
skyboxtop = Graphics.AddTexture("skybox_top.png");
skyboxbottom = Graphics.AddTexture("skybox_bottom.png");
Init openGL settings
void Init_OpenGL(void){
glClearDepth(1.f);
glClearColor(0.7f, 0.7f, 0.9f, 0.f);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 800.f / 600.f, 1.f, 500.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Lets openGL render a little nicer, at the expense of CPU usage.
std::cout << "You are running openGL Version: " << glGetString(GL_VERSION) << std::endl;
}
Main Loop
while (isRunning){
sf::Event _Evn;
while (Screen->pollEvent(_Evn)){
if (_Evn.type == sf::Event::Closed)
isRunning = false;
if (_Evn.type == sf::Event::Resized)
glViewport(0, 0, _Evn.size.width, _Evn.size.height);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Same as SFML clear, but with some Buffering ;)
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 800.f / 600.f, 1.f, 500.f);
this->Update(); //Draw skybox is called here!
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
this->Draw(); //Other models.
Screen->display();
}
Screen->close();
}
Drawing skybox (textures are REALLY blurry)
I disable a few things here, to get the Skybox effect, that part works, but the textures do not!
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glDisable(GL_BLEND);
float halfSize = 50.f;
// Render the front quad
glColor3f(1.f, 1.f, 1.f);
float EndCoordinate = 1;
glBindTexture(GL_TEXTURE_2D, 1);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( halfSize, -halfSize, -halfSize );
glTexCoord2f(EndCoordinate, 0); glVertex3f( -halfSize, -halfSize, -halfSize );
glTexCoord2f(EndCoordinate, EndCoordinate); glVertex3f( -halfSize, halfSize, -halfSize );
glTexCoord2f(0, EndCoordinate); glVertex3f( halfSize, halfSize, -halfSize );
glEnd();
// Render the left quad
glBindTexture(GL_TEXTURE_2D, 2);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( halfSize, -halfSize, halfSize );
glTexCoord2f(EndCoordinate, 0); glVertex3f( halfSize, -halfSize, -halfSize );
glTexCoord2f(EndCoordinate, EndCoordinate); glVertex3f( halfSize, halfSize, -halfSize );
glTexCoord2f(0, EndCoordinate); glVertex3f( halfSize, halfSize, halfSize );
glEnd();
glBindTexture(GL_TEXTURE_2D, 3);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( -halfSize, -halfSize, halfSize );
glTexCoord2f(EndCoordinate, 0); glVertex3f( halfSize, -halfSize, halfSize );
glTexCoord2f(EndCoordinate, EndCoordinate); glVertex3f( halfSize, halfSize, halfSize );
glTexCoord2f(0, EndCoordinate); glVertex3f( -halfSize, halfSize, halfSize );
glEnd();
// Render the right quad
glBindTexture(GL_TEXTURE_2D, 4);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( -halfSize, -halfSize, -halfSize );
glTexCoord2f(EndCoordinate, 0); glVertex3f( -halfSize, -halfSize, halfSize );
glTexCoord2f(EndCoordinate, EndCoordinate); glVertex3f( -halfSize, halfSize, halfSize );
glTexCoord2f(0, EndCoordinate); glVertex3f( -halfSize, halfSize, -halfSize );
glEnd();
// Render the top quad
glBindTexture(GL_TEXTURE_2D, 5);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( -halfSize, halfSize, -halfSize );
glTexCoord2f(EndCoordinate, 0); glVertex3f( -halfSize, halfSize, halfSize );
glTexCoord2f(EndCoordinate, EndCoordinate); glVertex3f( halfSize, halfSize, halfSize );
glTexCoord2f(0, EndCoordinate); glVertex3f( halfSize, halfSize, -halfSize );
glEnd();
// Render the bottom quad
glBindTexture(GL_TEXTURE_2D, 6);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f( -halfSize, -halfSize, -halfSize );
glTexCoord2f(EndCoordinate, 0); glVertex3f( -halfSize, -halfSize, halfSize );
glTexCoord2f(EndCoordinate, EndCoordinate); glVertex3f( halfSize, -halfSize, halfSize );
glTexCoord2f(0, EndCoordinate); glVertex3f( halfSize, -halfSize, -halfSize );
glEnd();
glEnable(GL_DEPTH_TEST);
//glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
I'm fairly new to openGL, so excuse any noob mistakes :p
I'm thoroughly stumped, but i'm sure it's just my fault...
I posted in the SFML window forum because i'm not 100% sure what the issue is, I just know it happened after I switched SFML versions from 1.6 -> 2.0
Did I miss a change in SFML 2 that affects openGL?