You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use go-gl and osmesa to render and output a simple triangle to a png file. I try to build and run in a Docker container (images are based on Ubuntu/CentOS). The problem is obtaining the version of OpenGL and renderer has failed although there is no error in gl.Init(). Shader compilation also fails with no log. It seems no OpenGL functions are loaded correctly.
In addition, the same code has been built and runs as expected in Alpine docker container, which is so strange.
What did you do?
Here is a minimal example of the code I used:
package main
/*#cgo linux LDFLAGS: -lOSMesa#cgo pkg-config: osmesa#include <GL/osmesa.h>*/import"C"import (
"fmt""runtime""unsafe""github.com/go-gl/gl/v4.1-core/gl"
)
// keep same with https://github.com/go-gl/osmesatype (
FormatintPixelTypeintContext C.OSMesaContext
)
funcCreateContext(formatFormat, sharelistContext) Context {
returnContext(C.OSMesaCreateContext(C.GLenum(format), C.OSMesaContext(sharelist)))
}
funcMakeCurrent(ctxContext, buffer unsafe.Pointer, type_PixelType,
widthint, heightint) bool {
return0!=C.OSMesaMakeCurrent(C.OSMesaContext(ctx), buffer, C.GLenum(type_),
C.GLsizei(width), C.GLsizei(height))
}
funcmain() {
runtime.LockOSThread()
mesaCtx:=CreateContext(gl.RGBA, nil)
ifmesaCtx==nil {
panic("failed to create context") // no panic when running
}
buffer:=make([]byte, 800*600*4)
if!MakeCurrent(mesaCtx, unsafe.Pointer(&buffer[0]), gl.UNSIGNED_BYTE, 800, 600) {
panic("failed to create buffer") // no panic when running
}
iferr:=gl.Init(); err!=nil {
panic(err)
}
version:=gl.GoStr(gl.GetString(gl.VERSION))
fmt.Println("OpenGL version", version) // ![output empty]!renderer:=gl.GoStr(gl.GetString(gl.RENDERER))
fmt.Println("Renderer", renderer) // output empty// ... shaders compilation also failed, gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logLength) set zero to logLength
}
Here are the Dockerfile for building and running.
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y build-essential cmake git wget pkg-config software-properties-common libx11-dev libxext-dev libxrender-dev \
libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libosmesa6-dev python3 python3-pip
RUN wget https://mirrors.aliyun.com/golang/go1.24.0.linux-amd64.tar.gz
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf go1.24.0.linux-amd64.tar.gz
RUN echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
WORKDIR /app
FROM centos:7
RUN echo go version
RUN sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/*.repo && \
sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo && \
sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo && \
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum update -y && yum install mesa-libGL-devel -y && yum install wget -y
RUN wget https://mirrors.aliyun.com/golang/go1.24.0.linux-amd64.tar.gz
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf go1.24.0.linux-amd64.tar.gz
RUN echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile && source /etc/profile
RUN yum install -y gcc make mesa-libGLU-devel mesa-libOSMesa-devel
ENV PATH=$PATH:/usr/local/go/bin
The only success is Alpine
FROM alpine:3
RUN apk add --no-cache build-base mesa-dev mesa-egl mesa-gles libx11-dev wget
RUN wget https://mirrors.aliyun.com/golang/go1.24.0.linux-amd64.tar.gz
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf go1.24.0.linux-amd64.tar.gz
RUN echo "export PATH=$PATH:/usr/local/go/bin" >> /etc/profile
What did you expect to happen?
The program runs as in Alpine. Here is the output in Alpine
What are you trying to do?
I am trying to use go-gl and osmesa to render and output a simple triangle to a png file. I try to build and run in a Docker container (images are based on Ubuntu/CentOS). The problem is obtaining the version of OpenGL and renderer has failed although there is no error in gl.Init(). Shader compilation also fails with no log. It seems no OpenGL functions are loaded correctly.
In addition, the same code has been built and runs as expected in Alpine docker container, which is so strange.
What did you do?
Here is a minimal example of the code I used:
Here are the Dockerfile for building and running.
The only success is Alpine
What did you expect to happen?
The program runs as in Alpine. Here is the output in Alpine
What actually happened?
The program outputs empty version and renderer string in CentOS 7.9, Ubuntu 24.04 and 22.04. Shader compilation and arrays drawing will also fail.
What version of Go and go-gl are you using?
Go 1.24
github.com/go-gl/gl v0.0.0-20231021071112-07e5d0ea2e71
I am new to OpenGL. Could you please help me with the below problem?
The text was updated successfully, but these errors were encountered: