Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4151

OpenGLES • Having trouble getting any approach to render an empty window at 60FPS

$
0
0
Hi,

My goal is to render a full screen shader at 60FPS on the pi either on a pi4 or a pi5.

However, I can't find a way to even render a blank screen at 60FPS (i.e. no shaders at all).

I first tried using freeGlut. I get 60FPS in large windows, but not full screen.

Code:

#include <GL/glew.h>#include <GL/freeglut.h>#include <GL/glu.h>#include <stdio.h>#include <string.h>#include <sys/time.h>#include <math.h>int frameCount = 0;struct timeval tv;unsigned long time_in_micros;unsigned long oldTime;void renderFunction(void) {    frameCount++;    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glutSwapBuffers();    if (frameCount % 10 == 0) {        oldTime = time_in_micros;        gettimeofday(&tv,NULL);        time_in_micros = 1000000 * tv.tv_sec + tv.tv_usec;        printf("Interframe time is %f\n", (float)(time_in_micros-oldTime)/10000);    }}void idleFunction(void) {  glutPostRedisplay();}int main(int argc, char* argv[]) {    gettimeofday(&tv,NULL);    time_in_micros = 1000000 * tv.tv_sec + tv.tv_usec;    glutInit(&argc, argv);    glewExperimental = GL_TRUE;    glewInit();    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);    int windowHandle = glutCreateWindow("Animation Across the nation");    //glutFullScreen();    glutDisplayFunc(renderFunction);    glutIdleFunc(idleFunction);    glutMainLoop();    exit(EXIT_SUCCESS);}
I know freeglut is old, so then tried glfw. Here, I get incredible FPS in large windows (only a few pixels below full screen), but again, as soon as I make it full screen I get 30FPS. Again, stressing, I am not rendering anything, just swapping buffers.

Code:

#include <stdio.h>#include <GLFW/glfw3.h>#include <sys/time.h>struct timeval tv;unsigned long  frameCount = 0,  time_in_micros,  oldTime;int main(void) {    glfwInit();    GLFWmonitor* primaryMonitor = glfwGetPrimaryMonitor();    const GLFWvidmode* mode = glfwGetVideoMode(primaryMonitor);        //Swapping between these two versions are what causes problems.    //GLFWwindow* window = glfwCreateWindow(1920, 1180, "My Title", NULL, NULL);    GLFWwindow* window = glfwCreateWindow(1920, 1200, "My Title", primaryMonitor, NULL);    glfwMakeContextCurrent(window);    glfwSwapInterval(0);    while (!glfwWindowShouldClose(window)) {        frameCount++;        glfwSwapBuffers(window);        if (frameCount % 10 == 0) {            oldTime = time_in_micros;            gettimeofday(&tv,NULL);            time_in_micros = 1000000 * tv.tv_sec + tv.tv_usec;            printf("Interframe time is %f\n", (float)(time_in_micros-oldTime)/10000);        }    }    glfwTerminate();    return 0;}
Neither approach is fixed by swapping from Wayland to X11.

I can get this version to work:
https://github.com/alanbork/rpi-opengl- ... gle_rpi4.c

But it seems like a lot... I've been googling this for days, but keep finding advice that relies on turning on the fake KMS driver.

What is the modern approach to get an openGL (ES?) context on the Pi. I'd love to use Weyland if it worked. Any links? They used to ship the Pi with an approved "hello triangle" example, and I sure wish they would again, as the internet is littered with old versions.

Statistics: Posted by bill.connelly — Thu May 16, 2024 5:56 am



Viewing all articles
Browse latest Browse all 4151

Trending Articles