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 - drummerp

Pages: 1 [2]
16
Window / OpenGL not rendering
« on: June 03, 2011, 02:24:59 am »
I'm afraid that didn't work, no... Thanks for trying.

17
Window / OpenGL not rendering
« on: May 31, 2011, 06:31:05 am »
My SFML window, rather than rendering a picture, appears as just a black box. Here's the relevant code:

Code: [Select]
BEGIN_EVENT_TABLE(wxSFMLCanvas, wxControl)
    EVT_IDLE(wxSFMLCanvas::OnIdle)
    EVT_PAINT(wxSFMLCanvas::OnPaint)
    EVT_SIZE(wxSFMLCanvas::OnSize)
    EVT_MOUSE_EVENTS(wxSFMLCanvas::OnClick)
    EVT_ERASE_BACKGROUND(wxSFMLCanvas::OnEraseBackground)
END_EVENT_TABLE()

void wxSFMLCanvas::OnUpdate() {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glTranslatef(0.0f, 0.0f, 200.0f);

    //Sample model...
    glBegin(GL_QUADS);
        glColor3f(0.1f, 1.0f, 0.1f);

        glVertex3f(100.0f, 0.0f, 100.0f);
        glNormal3f(100.0f, 1.0f, 100.0f);

        glVertex3f(100.0f, 0.0f, -100.0f);
        glNormal3f(100.0f, 1.0f, -100.0f);

        glVertex3f(-100.0f, 0.0f, -100.0f);
        glNormal3f(-100.0f, 1.0f, -100.0f);

        glVertex3f(-100.0f, 0.0f, 100.0f);
        glNormal3f(-100.0f, 1.0f, 100.0f);

        glVertex3f(-100.0f, 100.0f, 100.0f);
        glNormal3f(-100.0f, 101.0f, 100.0f);

        glVertex3f(-100.0f, 100.0f, -100.0f);
        glNormal3f(-100.0f, 101.0f, -100.0f);

        glVertex3f(100.0f, 100.0f, -100.0f);
        glNormal3f(100.0f, 101.0f, -100.0f);

        glVertex3f(100.0f, 100.0f, 100.0f);
        glNormal3f(100.0f, 101.0f, 100.0f);
    glEnd();

    glFlush();
}


void wxSFMLCanvas::OnIdle(wxIdleEvent& event) {
    //Send a paint message when the display is idle, for maximum framerate
    Refresh();
}

void wxSFMLCanvas::OnPaint(wxPaintEvent& event) {
    //Prepare the control to be repainted
    wxPaintDC dc(this);

    //Create the actual image
    OnUpdate();

    //Display the image on-screen
    Display();
}

void wxSFMLCanvas::OnEraseBackground(wxEraseEvent& event){
}

void wxSFMLCanvas::OnClick(wxMouseEvent& event) {
    ((wxFrame*)GetParent())->SetStatusText(wxT("Clicked the edit window."));
}

void wxSFMLCanvas::OnSize(wxSizeEvent& event) {
    if (initialised)
        ChangeSize(event.GetSize().GetWidth(), event.GetSize().GetHeight());
}

void wxSFMLCanvas::Setup() {
    std::cout << "Setting up rendering context." << std::endl;
    std::cout << "OpenGL vendor: " << glGetString(GL_VENDOR) << std::endl;
    std::cout << "OpenGL renderer: " << glGetString(GL_RENDERER) << std::endl;
    std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
    this->PreserveOpenGLStates(true);
    glEnable(GL_MULTISAMPLE);
    glEnable(GL_LIGHTING);
    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
    glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
    GLfloat ambient[] = {1.0f, 1.0f, 1.0f, 1.0f};
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
    this->SetActive(true);
    initialised = true;
}

void wxSFMLCanvas::ChangeSize(GLfloat w, GLfloat h) {
    GLfloat fAspect;

    // Prevent a divide by zero, when window is too short
    // (you cant make a window of zero width).
    if(h == 0)
        h = 1;

    glViewport(0, 0, w, h);

    fAspect = (GLfloat)w / (GLfloat)h;

    // Reset the coordinate system before modifying
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    // Set the clipping volume
    gluPerspective(35.0f, fAspect, 1.0f, 50.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
wxControl(Parent, Id, Position, Size, Style)
{
    std::cout << "wxSFMLCanvas constructor entered." << std::endl;
    #ifdef __WXGTK__

        // GTK implementation requires to go deeper to find the
        // low-level X11 identifier of the widget
        std::cout << "Realizing wxWidget window." << std::endl;
        gtk_widget_realize(m_wxwindow);
        std::cout << "Removing double-buffering from GTK." << std::endl;
        gtk_widget_set_double_buffered(m_wxwindow, false);
        std::cout << "Getting X11 handle." << std::endl;
        GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window;
        std::cout << "Flushing buffer." << std::endl;
        XFlush(GDK_WINDOW_XDISPLAY(Win));
        std::cout << "Creating RenderWindow." << std::endl;
        sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(Win));

    #else

        // Tested under Windows XP only (should work with X11
        // and other Windows versions - no idea about MacOS)
        sf::RenderWindow::Create(GetHandle());

    #endif
    Setup();
}

wxSFMLCanvas::~wxSFMLCanvas() {
}


In theory, this should be drawing a green box in the centre of the screen, yes? But it's not working... If anyone could provide any help, I'd really appreciate it. If there's any more information you need, I'd be glad to supply.

18
Window / wxWidgets sample segfault
« on: March 18, 2011, 04:53:31 am »
I am currently designing a program which uses the wxWidgets windowing library. I have a need for a 3D renderer in my program, and so I decided to use SFML for this as I had had prior experience with SFML and found it very useful and simple. I found the tutorial on integration with wxWidgets, and, erm...based my code off of it, shall we say? I have changed it and made it significantly different. However, it is still a class called wxSFMLCanvas, and the constructor is the same (aside from the debug calls to cout and the call to my function Setup() at the end):

Code: [Select]
wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
wxControl(Parent, Id, Position, Size, Style)
{
    std::cout << "wxSFMLCanvas constructor entered." << std::endl;
    #ifdef __WXGTK__

        // GTK implementation requires to go deeper to find the
        // low-level X11 identifier of the widget
        std::cout << "Realizing wxWidget window." << std::endl;
        gtk_widget_realize(m_wxwindow);
        std::cout << "Removing double-buffering from GTK." << std::endl;
        gtk_widget_set_double_buffered(m_wxwindow, false);
        std::cout << "Getting X11 handle." << std::endl;
        GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window;
        std::cout << "Flushing buffer." << std::endl;
        XFlush(GDK_WINDOW_XDISPLAY(Win));
        std::cout << "Creating RenderWindow." << std::endl;
        sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(Win));
        std::cout << "Created RenderWindow from X11 widget." << std::endl;

    #else

        // Tested under Windows XP only (should work with X11
        // and other Windows versions - no idea about MacOS)
        sf::RenderWindow::Create(GetHandle());
        std::cout << "Created RenderWindow from handle." << std::endl;

    #endif
    Setup();
}


I am currently using wxGTK on a Linux system for this. I added the calls to cout after I discovered this problem. When the constructor is called, "wxSFMLCanvas constructor entered." and "Realizing wxWidget window." are printed, but then I get a segfault on the line gtk_widgets_realize(m_wxwindow); I am not familiar with the GTK+ libraries, or that function at all. I assume it's a problem with my m_wxwindow being a NULL pointer.

If this is something I should rather be asking in the wxWidgets forums than here, please let me know. I'm not really aware of how that code works at all or what it does, and would really appreciate any help that can be given. If anyone has come across this before, or can tell why it would occur from the code, I am willing to try just about anything. I've been working on this project for several months now and would like to see it running.

EDIT: Never mind, I appear to have solved it. It was a problem with my code. gtk_widgets_realize() was, at some point, telling it the size had changed, and so it was calling my OnSize function. The OnSize function has a few OpenGL calls, but since my RenderWindow was never initialise,d, there was no rendering context on which OpenGL could operate, leading to the segfault.

Pages: 1 [2]