Sunday, April 05, 2020

Notes on OpenGL programming with GLUT (freeglut3)

Wanted to create something like GL_warp2mp4 extending GL_warp2Avi using ffmpeg instead of vfw. Some notes on the process.


https://github.com/hn-88/GL_warp2Avi/blob/master/AVIGenerator.cpp
image buffer is bmBits


https://github.com/hn-88/GL_warp2Avi/blob/master/NeHeGL.h
defines structs like GL_Window

https://github.com/hn-88/GL_warp2Avi/blob/master/upate.htm
contains link to source, http://www.codeproject.com/audio/avigenerator.asp

https://www.codeproject.com/Articles/34472/Video-Texture-in-OpenGL
uses OpenGL,GLUT and OpenCV to draw video as a texture.

Software manager showed that the current package needed for GLUT is freeglut3-dev

Also will need mesa-utils?
https://askubuntu.com/questions/96087/how-to-install-opengl-glut-libraries
(already installed)

Also, on error,
sudo apt-get install libxmu-dev libxi-dev

undefined reference to symbol 'glEnable'
//usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
link order is important?
https://stackoverflow.com/questions/23729213/link-error-when-trying-to-build-a-simple-opengl-program
So,  ${GLUT_LIBRARY} in the CMakeLists.txt is not enough?
-lGL -lGLU  -lglut works!
On my system, for making a simple hello world GLUT  app,
g++ hello.c -lGL -lGLU -lglut -o hello

For Paul Bourke's code from http://paulbourke.net/miscellaneous/lens/
gcc -Wall lens.c -lm -lGL -lGLU -lglut -o lens.bin
(since C++ does not allow casts of void* to other types, not g++, but gcc.

https://stackoverflow.com/questions/42407390/g-error-invalid-conversion-from-void-to-info-fpermissive-error-inval


https://askubuntu.com/questions/527665/undefined-reference-to-symbol-expglibc-2-2-5

so added -lm for math.h
)

OCVWarp speeds - using opencv functions on Lenovo B460,
stock.webm input VP8, 596x336
45 fps without remap, or resizing,
27 fps if resizing to 1920x1080
18 fps with remap, without writing to disk
12 fps writing Xvid

GL_warp2mp4 speeds - using opengl for resizing etc
60 fps for 640x480 texture,
60 fps for 1920x1080 viewport also.
30 fps for 1920x1080 viewport w avc1 960x480 input.
But glReadPixels slows it down to 1 fps
Also, only un-resized texture is read when viewport is bigger than screen size?!

Double buffer to make it faster?
https://stackoverflow.com/questions/39821850/why-is-glreadpixels-so-slow-and-are-there-any-alternative

http://www.songho.ca/opengl/gl_pbo.html
when trying to make, gave error,
‘glGenBuffers’ was not declared in this scope
https://community.khronos.org/t/glgenbuffers-was-not-declared-in-this-scope/59283
adding this #define to the beginning of the code
#define GL_GLEXT_PROTOTYPES
and
#include "glext.h"
solved the problem.

glReadPixels slowed down pboUnpack
from 30 to 20 fps with PBO,
20 to 14 fps wo PBO
when changed from GL_BGRA to GL_BGR as needed for opencv, went down to 2 fps. So, a proper choice of PIXEL_FORMAT - GL_BGRA - and proper double buffering, should increase speeds.

frame buffer to viewport scaling etc
https://gamedev.stackexchange.com/questions/72677/how-to-make-opengl-rendering-resolution-independent-from-its-window-context-reso

Current GL_warp2mp4 works at 10 fps, but only if the viewport is smaller than screen size. Todo - do the actual warping by incorporating code from GL_warp2Avi.




No comments:

Post a Comment