Displays content (sometimes).
authorCarl Hetherington <cth@carlh.net>
Sun, 20 Jan 2019 00:41:59 +0000 (00:41 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 6 May 2019 20:31:09 +0000 (21:31 +0100)
src/wx/film_viewer.cc
src/wx/gl_view.cc
src/wx/gl_view.h

index ca89e3a83fb4183bf4b7aab8e4c8777902727edf..acbbcdd25043d0af31de9c996a5cc6929ee0863b 100644 (file)
@@ -272,7 +272,7 @@ FilmViewer::display_player_video ()
        _state_timer.set ("get image");
        /* XXX: do we need to store _frame? */
        _frame = _player_video.first->image (bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true);
-       _gl_view->set_image ();//_frame);
+       _gl_view->set_image (_frame);
 
        _state_timer.set ("ImageChanged");
        ImageChanged (_player_video.first);
index c77e795c3a8d48972a792634ce5753dccf4cbfe7..5edfdc91ead641b314cf7c06ac635de24e97704a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2018-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -20,6 +20,7 @@
 
 #include "gl_view.h"
 #include "lib/image.h"
+#include "lib/dcpomatic_assert.h"
 #include <boost/bind.hpp>
 #include <iostream>
 
@@ -30,7 +31,6 @@ using boost::shared_ptr;
 
 GLView::GLView (wxWindow *parent)
        : wxGLCanvas (parent, wxID_ANY, 0, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
-       , _have_texture (false)
 {
        _context = new wxGLContext (this);
        Bind (wxEVT_PAINT, boost::bind(&GLView::paint, this, _1));
@@ -88,17 +88,17 @@ GLView::paint (wxPaintEvent &)
 
        glTranslatef (0, 0, 0);
 
-       if (_have_texture) {
+       if (_size) {
                glBegin (GL_QUADS);
 
                glTexCoord2f (0, 1);
-               glVertex2f (0, 0);
+               glVertex2f (0, _size->height);
                glTexCoord2f (1, 1);
-               glVertex2f (1024, 0);
+               glVertex2f (_size->width, _size->height);
                glTexCoord2f (1, 0);
-               glVertex2f (1024, 1024);
+               glVertex2f (_size->width, 0);
                glTexCoord2f (0, 0);
-               glVertex2f (0, 1024);
+               glVertex2f (0, 0);
 
                glEnd ();
        }
@@ -108,34 +108,12 @@ GLView::paint (wxPaintEvent &)
 }
 
 void
-GLView::set_image ()
+GLView::set_image (shared_ptr<const Image> image)
 {
-       int const width = 1024;
-       int const height = 1024;
-       unsigned char foo[width * height * 3];
-       unsigned char* p = foo;
-       for (int y = 0; y < height; ++y) {
-               for (int x = 0; x < width; ++x) {
-                       if (((y / 16) % 3) == 0) {
-                               *p++ = char(x * 256 / width);
-                       } else {
-                               *p++ = 0;
-                       }
-                       if (((y / 16) % 3) == 1) {
-                               *p++ = char(x * 256 / width);
-                       } else {
-                               *p++ = 0;
-                       }
-                       if (((y / 16) % 3) == 2) {
-                               *p++ = char(x * 256 / width);
-                       } else {
-                               *p++ = 0;
-                       }
-               }
-       }
+       DCPOMATIC_ASSERT (image->pixel_format() == AV_PIX_FMT_RGB24);
 
-       glTexImage2D (GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, foo);
-       _have_texture = true;
+       _size = image->size ();
+       glTexImage2D (GL_TEXTURE_2D, 0, 3, image->size().width, image->size().height, 0, GL_RGB, GL_UNSIGNED_BYTE, image->data()[0]);
 
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
index ce8af69da7c21f210e6792adb54f422c5047ba1c..42d3ae8c8020f3fb1eba2ff6c4f3ce3a622bd866 100644 (file)
@@ -33,12 +33,12 @@ public:
        GLView (wxWindow* parent);
        virtual ~GLView ();
 
-       void set_image ();
+       void set_image (boost::shared_ptr<const Image> image);
 
 private:
        void paint (wxPaintEvent& event);
 
        wxGLContext* _context;
        GLuint _id;
-       bool _have_texture;
+       boost::optional<dcp::Size> _size;
 };