{"id":956,"date":"2012-04-10T21:56:07","date_gmt":"2012-04-10T13:56:07","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=956"},"modified":"2012-04-10T21:56:07","modified_gmt":"2012-04-10T13:56:07","slug":"directshow-for-processing-opengl","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2012\/04\/10\/directshow-for-processing-opengl\/","title":{"rendered":"DirectShow for Processing &#8211; OpenGL"},"content":{"rendered":"<p>I try to work out another version of the DirectShow for Processing classes in the <a href=\"http:\/\/www.magicandlove.com\/blog\/2012\/04\/10\/directshow-for-processing\/\">last post<\/a>. In this version, I write the movie data directly to an OpenGL texture object. Below is the modified version of the DMovie class. The DCapture class can also be modified in the same way.<br \/>\n&nbsp;<br \/>\n<strong>The modified DMovie class<\/strong><\/p>\n<pre lang=\"java\">\r\nimport de.humatic.dsj.*;\r\nimport java.awt.image.BufferedImage;\r\nimport com.sun.opengl.util.texture.*;\r\n\r\nclass DMovie implements java.beans.PropertyChangeListener {\r\n\r\n  private DSMovie movie;\r\n  public int width, height;\r\n  public Texture tex;\r\n\r\n  DMovie(String _s) {\r\n    movie = new DSMovie(dataPath(_s), DSFiltergraph.DD7, this);\r\n    movie.setVolume(1.0);\r\n    movie.setLoop(false);\r\n    movie.play();\r\n    width = movie.getDisplaySize().width;\r\n    height = movie.getDisplaySize().height;\r\n    tex = TextureIO.newTexture(movie.getImage(), false);\r\n  }\r\n\r\n  public void updateImage() {\r\n    BufferedImage bimg = movie.getImage();\r\n    TextureData td = TextureIO.newTextureData(bimg, false);\r\n    tex.updateImage(td);\r\n  }\r\n\r\n  public void loop() {\r\n    movie.setLoop(true);\r\n    movie.play();\r\n  }\r\n\r\n  public void play() {\r\n    movie.play();\r\n  }\r\n\r\n  public void propertyChange(java.beans.PropertyChangeEvent e) {\r\n    switch (DSJUtils.getEventType(e)) {\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>&nbsp;<br \/>\n<strong>Sample code that uses the new DMovie class<\/strong><\/p>\n<pre lang=\"java\">\r\nimport processing.opengl.*;\r\nimport javax.media.opengl.*;\r\n\r\nDMovie mov;\r\nPGraphicsOpenGL pgl;\r\n\r\nvoid setup()\r\n{\r\n  size(1280, 692, OPENGL);\r\n  pgl = (PGraphicsOpenGL) g;\r\n  GL gl = pgl.beginGL();\r\n  background(0);\r\n  mov = new DMovie(\"Hugo.mp4\");\r\n  mov.loop();\r\n  mov.tex.bind();\r\n  pgl.endGL();\r\n  ;\r\n}\r\n\r\nvoid draw()\r\n{\r\n  GL gl = pgl.beginGL();\r\n  mov.updateImage();\r\n  mov.tex.enable();\r\n  gl.glBegin(GL.GL_QUADS);\r\n  gl.glTexCoord2f(0, 0); \r\n  gl.glVertex2f(0, 0);\r\n  gl.glTexCoord2f(1, 0); \r\n  gl.glVertex2f(width, 0);\r\n  gl.glTexCoord2f(1, 1); \r\n  gl.glVertex2f(width, height);\r\n  gl.glTexCoord2f(0, 1); \r\n  gl.glVertex2f(0, height);\r\n  gl.glEnd();  \r\n\r\n  mov.tex.disable();\r\n  pgl.endGL();\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I try to work out another version of the DirectShow for Processing classes in the last post. In this version, I write the movie data directly to an OpenGL texture object. Below is the modified version of the DMovie class. The DCapture class can also be modified in the same way. &nbsp; The modified DMovie [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[79,66],"tags":[102,75,62],"class_list":["post-956","post","type-post","status-publish","format-standard","hentry","category-software-2","category-testing","tag-directshow","tag-opengl","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/956","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=956"}],"version-history":[{"count":1,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/956\/revisions"}],"predecessor-version":[{"id":957,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/956\/revisions\/957"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=956"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}