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

Author Topic: Black Screen [iOS] [SOLVED]  (Read 2947 times)

0 Members and 1 Guest are viewing this topic.

inzombiak

  • Newbie
  • *
  • Posts: 3
    • View Profile
Black Screen [iOS] [SOLVED]
« on: May 04, 2016, 05:56:07 pm »
I've been working with SFML for a while now and I love it. I recently decided to test it out on iOS and while I know its not fully functional I wanted to see how feasible it was.
I read the forums and managed to compile SFML and get it working. The problem is, the screen on my iPhone goes black.

Here is the code I have.
#import <iostream>
#include <SFML/Main.hpp>
#include <SFML/Graphics.hpp>

int main(int argc, char * argv[])
{

    std::cout << "HELLo" << std::endl;

    sf::RenderWindow rw;
    rw.create(sf::VideoMode(700, 1334), "Hi");
    rw.setPosition(sf::Vector2i(50, 50));
    rw.clear(sf::Color::Red);
    rw.display();

    sf::RectangleShape rect;
    rect.setSize(sf::Vector2f(50, 50));
    rect.setPosition(sf::Vector2f(100, 100));
    rect.setFillColor(sf::Color::Green);

    rw.draw(rect);
    rw.display();

    return 0;
}
 


Anyone know what I'm doing wrong? I dont get any errors and the cout works.
« Last Edit: May 05, 2016, 04:09:08 pm by inzombiak »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Black Screen [iOS]
« Reply #1 on: May 04, 2016, 08:15:39 pm »
I don't know if it's what's causing your problem. But; 1) your program draws two frames and doesn't clear the screen between them - you should clear/draw/display for every frame. 2) your program exits very quickly (after drawing just two frames) - what does iOS do then? I don't know, but reverting to a black screen doesn't sound unreasonable.

inzombiak

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Black Screen [iOS]
« Reply #2 on: May 05, 2016, 01:48:30 pm »
Thanks for the reply.
I'm aware of that, but it should still display something before the program exits right? I've tried the same code in a "while(true)" loop with  the clear/draw/display steps, but it didnt help. I started from scratch, but now I get a "An internal OpenGL call failed in RenderTarget.cpp (355) : GL_INVALID_ENUM, an unacceptable value has been specified for an enumerated argument" error at rw.display(). At first I was getting the same error in Texture.cpp, but after updating the libjpeg.a file for arm64, that one went away.

EDIT: Never mind, still get the Texture.cpp error after calling rw.clear(sf::Color::Red). The error I get is
"An internal OpenGL call failed in Texture.cpp (556) : GL_INVALID_ENUM, an unacceptable value has been specified for an enumerated argument"

EDIT 2: Managed to fix the errors by adding this line #import <OpenGLES/ES2/gl.h>, still getting a black screen.

Edit 3: Got it working. Turns out you HAVE to poll for events on iOS or at least that's what fixed it for me. Here's my code in case anyone needs it in the future.

#import <iostream>
#import <OpenGLES/ES2/gl.h>
#include <SFML/Main.hpp>
#include <SFML/Graphics.hpp>

#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>


int main(int argc, char * argv[])
{
    sf::RenderWindow rw(sf::VideoMode(700, 1334), "Hi", sf::Style::Fullscreen ,sf::ContextSettings(32));
    bool running = true;
    sf::RectangleShape rect;
    rect.setSize(sf::Vector2f(50, 50));
    rect.setPosition(sf::Vector2f(100, 100));
    rect.setFillColor(sf::Color::Green);
   
    while (running)
    {
        // handle events
        sf::Event event;
        while (rw.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                // end the program
                running = false;
            }
            else if (event.type == sf::Event::Resized)
            {
                // adjust the viewport when the window is resized
                glViewport(0, 0, event.size.width, event.size.height);
            }
        }
       
        rw.clear(sf::Color::Red);
       
        rw.draw(rect);
       
        rw.display();

    }
    return 0;
}
« Last Edit: May 05, 2016, 04:08:34 pm by inzombiak »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Black Screen [iOS] [SOLVED]
« Reply #3 on: May 05, 2016, 04:18:33 pm »
Good to hear you got it working :-)