1
General discussions / The new graphics API in SFML 2
« on: September 19, 2011, 09:51:02 pm »Quote
maybe sf::Transformable?
or sf::Spatial ?
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
maybe sf::Transformable?
#pragma comment(lib, "sfml-system.lib")
...
Did you consider using AssImp for loading 3d meshes?
i can read and set every pixel, but you cant read the alpha of an pixel from an qimage :O
QImage image;
...
QRgb pixel = image.pixel(x, y);
int alpha = qAlpha(pixel); // return your alpha component
QImage source;
...
QImage converted = QGLWidget::convertToGLFormat(source);
sf::Image final;
final.LoadFromPixels(source.width(), source.height(), reinterpret_cast<const sf::Uint8*>(converted.bits()));
so you should include all your opengl calls within App.SaveGLStates(); and App.RestoreGLStates();
gluPerspective(70.f, static_cast<float>(App.GetWidth()) / static_cast<float>(App.GetHeight()), 1.f, 600.f);
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
int main()
{
sf::Clock clock;
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML + OpenGL", sf::Style::Default, sf::ContextSettings(32));
float red[] = {102.f/255.f, 51.f/255.f, 51.f/255.f};
float blue[] = {51.f/255.f, 51.f/255.f, 102.f/255.f};
float green[] = {51.f/255.f, 102.f/255.f, 51.f/255.f};
GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0};
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_position[] = {0.0, 0.0, 1.0, 0.0};
while (App.IsOpened())
{
sf::Event Event;
while (App.PollEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
App.Clear(sf::Color(0, 0, 0, 1));
App.SaveGLStates();
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glClearDepth(1.f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.f, static_cast<float>(App.GetWidth()) / static_cast<float>(App.GetHeight()), 1.f, 600.f);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
glRotatef(clock.GetElapsedTime() * 50, 1.f, 0.f, 0.f);
glRotatef(clock.GetElapsedTime() * 30, 0.f, 1.f, 0.f);
glRotatef(clock.GetElapsedTime() * 90, 0.f, 0.f, 1.f);
// Draw a cube
glBegin(GL_QUADS);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
glColor3f(1.f, 0.f, 0.f);
glNormal3f(0.f, 0.f, -1.f);
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);
glColor3f(1.f, 0.f, 0.f);
glNormal3f(0.f, 0.f, 1.f);
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);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
glColor3f(0.f, 1.f, 0.f);
glNormal3f(-1.f, 0.f, 0.f);
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);
glColor3f(0.f, 1.f, 0.f);
glNormal3f(1.f, 0.f, 0.f);
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);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
glColor3f(0.f, 0.f, 1.f);
glNormal3f(0.f, -1.f, 0.f);
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);
glColor3f(0.f, 1.f, 0.f);
glNormal3f(0.f, 1.f, 0.f);
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();
App.RestoreGLStates();
App.Display();
}
return EXIT_SUCCESS;
}