Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - Groogy

Pages: 1 ... 87 88 [89]
1321
Graphics / Images and OpenGL
« on: January 17, 2009, 12:00:47 am »
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.

Code: [Select]
#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;
}
}
}

1322
Graphics / Images and OpenGL
« 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.

Pages: 1 ... 87 88 [89]