Hey everyone, I need to create some perspective, I tried convex shapes, vertex arrays and shaders... no avail, that is why I found myself looking at raw openGL.
I'm pretty well versed in DirectX but this is the first time I've looked into openGL, so far so good and I have created the perspective without problems. However I'm not trying to texture my square, this will probably be a simple fix but I have no idea so please help me.
#include "stdafx.h"
#include <iostream>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
#include <SFML/Graphics.hpp>
#include <gl/GLU.h>
int main()
{
// Create window
sf::RenderWindow window(sf::VideoMode(0,0,1024, 768), "SFML Perspective");
//load the texture
sf::Texture texture;
if (!texture.loadFromFile("images\\images.png"))
{
return EXIT_SUCCESS;
}
texture.setRepeated(true);
//initialise OPENGL
glClearDepth(1.0f);
glClearColor(1.f, 1.0f, 1.0f, 0.0f);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
//// Setup the camera
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0f, 1.0f, 1.0f, 500.0f);
// Game loop
while (window.isOpen())
{
// Process events
sf::Event Event;
while (window.pollEvent(Event))
{
if (Event.type == sf::Event::Closed)
{
window.close();
}
}
// Clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Preform the appropriate transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -150.f);
glRotatef(30.0f, 0.f, 1.f, 0.f);
glEnable(GL_TEXTURE_2D);
sf::Texture::bind(&texture);
//Draw a face
glBegin(GL_QUADS);
{
glColor3f(0, 0, 1);
glVertex3f(-50.f, -50.f, 50.f);
glVertex3f(-50.f, 50.f, 50.f);
glVertex3f(50.f, 50.f, 50.f);
glVertex3f(50.f, -50.f, 50.f);
}
glEnd();
sf::Texture::bind(NULL);
window.display();
}
return EXIT_SUCCESS;
}
That is my code nice and simple.
When I comment out all of the code to do with texturing namely:
sf::Texture texture;
if (!texture.loadFromFile("images\\images.png"))
{
return EXIT_SUCCESS;
}
texture.setRepeated(true);
...
glEnable(GL_TEXTURE_2D);
sf::Texture::bind(&texture);
...
sf::Texture::bind(NULL);
It works fine and I get (see attachment). When I put the lines of code back in I just get a black screen... what am I doing wrong, any help would be appreciated.