# Glfw examples ? (or general advice using opengl in julia)

**URL:** <https://discourse.julialang.org/t/glfw-examples-or-general-advice-using-opengl-in-julia/34558>\
**Category:** General Usage\
**Created:** [February 13, 2020, 5:51am UTC](https://discourse.julialang.org/t/glfw-examples-or-general-advice-using-opengl-in-julia/34558 "2020-02-13T05:51:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [February 13, 2020, 5:51am UTC](https://discourse.julialang.org/t/glfw-examples-or-general-advice-using-opengl-in-julia/34558/1 "2020-02-13T05:51:20Z")

</div>

From the Julia package GLFW page:

“The Julia interface is almost identical to the underlying C interface, with a few notable differences:”

while that’s true, figuring out how to translate things like,

```julia
 glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL);

```

into Julia is proving to be a bit of a task, consisting almost entierly of trial and error. This is really a more general question as to how to translate opengl code in general, thanks to opengl specific types, etc… for example,

```julia
const GLint vcol_location = glGetAttribLocation(program, "vCol");

glVertexAttribPointer(vcol_location, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*) offsetof(Vertex, col));

```

There’s a whole lotta learning curve here, and looking for something to help me get down that curve a little faster.

Thank you !

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [February 13, 2020, 12:31pm UTC](https://discourse.julialang.org/t/glfw-examples-or-general-advice-using-opengl-in-julia/34558/2 "2020-02-13T12:31:42Z")

</div>

Have you given ModernGL.jl a try? It wraps most (all?) of OpenGL’s API and makes it trivial to translate C/C++ OpenGL programs to Julia.

Also, for a comprehensive demo, my [DesignatedShader.jl](https://git.sr.ht/~jpsamaroo/DesignatedShader.jl) package/demo is a good reference point, IMO. Just clone it, change into the `DesignatedShader/` directory, and run `julia --project bin/main.jl` to run the demo. Currently it assumes you have OpenGL 3.3 available.

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [February 13, 2020, 2:29pm UTC](https://discourse.julialang.org/t/glfw-examples-or-general-advice-using-opengl-in-julia/34558/3 "2020-02-13T14:29:42Z")

</div>

I wrote some [simple step-by-step OpenGL demos](https://github.com/Gnimuc/Videre/tree/master/OpenGL%204%20Tutorials) a while ago , not all of them can work with the latest Julia though.

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [February 13, 2020, 6:50pm UTC](https://discourse.julialang.org/t/glfw-examples-or-general-advice-using-opengl-in-julia/34558/4 "2020-02-13T18:50:17Z")

</div>

> [@jpsamaroo](#):
>
> Have you given ModernGL.jl a try?

i tried to and, once again, had trouble finding examples of how it worked. Also, from the ModernGL page,

> [GLAbstraction](https://github.com/SimonDanisch/GLAbstraction.jl) is a library, that offers Julian wrappers around often used OpenGL functions and types.
> 
> [GLWindow](https://github.com/SimonDanisch/GLWindow.jl) essentially wraps GLFW (but might be extended to context creation methods) and gives you an easy way to create a window and access window events .
> 
> [GLVisualize](https://github.com/JuliaGL/GLVisualize.jl) Offers a simple to use API to create 2D/3D visualization and animations.

GLAbstraction and GLWindow seem to both be dead, or at least, dead to 1.3. then, somehow i got the impression that ModernGL depended on them, i think due to some crufty examples I was looking at, so i gave up on the whole lot of it. It didn’t help that ModernGL has not been updated very much lately (maybe because it just doesn’t need to be). I will go back to ModernGL with your example and see if i can make some progress.

> [@Gnimuc](#):
>
> I wrote some [simple step-by-step OpenGL demos](https://github.com/Gnimuc/Videre/tree/master/OpenGL%204%20Tutorials) a while ago , not all of them can work with the latest Julia though.

perfect! even if they don’t work, they will at least get me down the learning curve faster. I very much hope i can make them work and then contribute the changes. Julia needs solid opengl examples in the worst way…

Thanks very much for the suggestions !

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [February 14, 2020, 4:57pm UTC](https://discourse.julialang.org/t/glfw-examples-or-general-advice-using-opengl-in-julia/34558/5 "2020-02-14T16:57:05Z")

</div>

Quick note: you should comment out the following line to prevent an error: [~jpsamaroo/DesignatedShader.jl: bin/main.jl - sourcehut git](https://git.sr.ht/~jpsamaroo/DesignatedShader.jl/tree/master/bin/main.jl#L14)

I was working on rendering a cat mesh model, but haven’t yet gotten it to work well 😄

---

<div class="post-metadata">

**Author:** ![purplishrock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/purplishrock/32/13451_2.png) [@purplishrock](https://discourse.julialang.org/u/purplishrock)\
**Post date:** [February 14, 2020, 7:18pm UTC](https://discourse.julialang.org/t/glfw-examples-or-general-advice-using-opengl-in-julia/34558/6 "2020-02-14T19:18:43Z")

</div>

haha. ok. will do

@Gnimuc i have started on the demos. so far finding just a few issues. i have no idea how to do PRs, but if i can figure it out i’ll start moving my changes back to the tree. they are quite minor at this time. i’ve just found something a little tricky to handle, but i think i’ll figure it out, once i figure out how flipdims worked…

i find it very funny how often that colored triangle demo shows up. everybody takes it and it ends up being a demo in every language’s FFI to GLFW/OpenGL.

opengl programmers have something against cubes ? 😆

my first goal is to make a cube demo, and get into the demo project 😃
