SFML community forums
Help => Graphics => Topic started by: Groogy on January 16, 2009, 11:35:06 pm
-
Couldn't find any topics about this when I made a search.
Can I use like the pointer to the pixel data in a sf::Image to use as an texture or image with OpenGL? Kinda like you can do with SDL_Structures and OpenGL.
Ow yeah, can you also use Sprites? To just draw an image on the display while using OpenGL? Would simplify a lot of stuff. I tried myself but the image was kinda incomplete and it didn't show the entire image. Some random squares were black.
Keep in mind I'm just trying out SFML and thinking about moving from SDL to SFML.
-
You can do all this stuff. Just show us some code if something doesn't work ;)
-
Almost got it working. Got very many dots instead now spread over the image in rectangles or something. Kinda like spray in paint. Ow yeah, may be nothing but just now when I pressed the close button my X-Server crashed and I failed back to the login screen.
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;
sf::RenderWindow window;
const unsigned int MAX_FPS = 20;
void SetupWindow();
void SetupGL();
void ResizeGLScene(unsigned int width, unsigned int height);
void HandleEvents();
int main() {
SetupWindow();
sf::Image img;
sf::Sprite sprite;
img.LoadFromFile("ubuntu-tan2.jpg");
sprite.SetImage(img);
while(window.IsOpened()) {
window.Clear();
glLoadIdentity();
window.Draw(sprite);
window.Display();
HandleEvents();
}
return 0;
}
void SetupWindow() {
sf::WindowSettings settings;
settings.DepthBits = 24;
settings.StencilBits = 8;
settings.AntialiasingLevel = 2;
window.Create(sf::VideoMode(800, 600, 32), "Groogy App", sf::Style::Close, settings);
window.SetFramerateLimit(MAX_FPS);
window.SetActive(true);
SetupGL();
}
void SetupGL() {
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
void ResizeGLScene(unsigned int width, unsigned int height) {
if(height == 0)
{
height = 1;
}
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height,0.1f,100.0f);
}
void HandleEvents() {
sf::Event event;
while(window.GetEvent(event)) {
switch(event.Type) {
case sf::Event::Closed:
window.Close();
break;
case sf::Event::Resized:
ResizeGLScene(event.Size.Width, event.Size.Height);
break;
default:
break;
}
}
}
-
Wow, I fixed it, replaced: window.Clear() to glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); instead.
I used it before and it didn't help much, but it seems like I made something wrong that I must have changed.
-
window.Clear() doesn't clear the depth buffer.