Sign in to follow this  
Geometrian

OpenGL SEGFAULT with OpenGL ES glDrawArrays

Recommended Posts

Geometrian    1810
Hi,

I'm trying to draw simple things with OpenGL ES on a Raspberry Pi.

I created a context through the X system and the glx_create_context_es2_profile extension. This resulted in what I hope is an OpenGL ES 2.0 context (the testing functions gave weird values), but it seems to work for some things (e.g., it gave salient feedback on a shader, which it successfully compiled).

The code is:
GLint loc_vert = program->get_location_attribute("vertex");
printf("Loc vert=%d, vertex size=%d\n",loc_vert,sizeof(Vertex));
glEnableVertexAttribArray(loc_vert); glVertexAttribPointer(loc_vert, 4,GL_FLOAT, GL_FALSE, sizeof(Vertex),vertices);

printf("Begin glDrawArrays=%p with %d,%d,%d\n",glDrawArrays, mode,0,num_vertices);
glDrawArrays(mode, 0,num_vertices);
printf("End glDrawArrays=%p\n",glDrawArrays);

glDisableVertexAttribArray(loc_vert);
The "vertices" array is a static array of four vertices

The output is:

Loc vert=0, vertex size=68
Begin glDrawArrays=<some ptr> with 1,0,2
segfault

I checked against the documentation and my previous code, and this should be valid (it also runs fine on two other systems).

I took the liberty of disassembling glDrawArrays:

Dump of assembler code for function glDrawArrays:
0xb6e63500 <+0>: ldr r3, [pc, #42985368] ; 0xb6e63528 <glDrawArrays+40>
0xb6e63504 <+4>: push {r4, lr}
0xb6e63508 <+8>: mov r4, r0
0xb6e6350c <+12>: ldr r3, [pc, r3]
0xb6e63510 <+16>: bl 0xb6e6f110
0xb6e63514 <+20>: ldr r3, [r0, r3]
0xb6e63518 <+24>: mov r0, r4
0xb6e6351c <+28>: ldr r3, [r3, #3122144] ; 0x4d8
0xb6e63520 <+32>: blx r3
0xb6e63524 <+36>: pop {r4, pc}
0xb6e63528 <+40>: andeq r8, r1, r12, asr sp
End of assembler dump.

It segfaults on "0xb6e63510 <+16>", which is a jump.

Ideas?
-G Edited by Geometrian

Share this post


Link to post
Share on other sites
Geometrian    1810
After looking around at a related issue, I found this StackOverflow question. Therefore, I changed the code to:
GLint loc_vert = program->get_location_attribute("vertex");

GLuint vao;
glGenVertexArrays(1,&vao);
glBindVertexArray(vao);

GLuint vbo;
glGenBuffers(1,&vbo);
glBindBuffer(GL_ARRAY_BUFFER,vbo);
glBufferData(GL_ARRAY_BUFFER, num_vertices*sizeof(Vertex),vertices, GL_STATIC_DRAW);

glEnableVertexAttribArray(loc_vert);
glVertexAttribPointer(loc_vert, 4,GL_FLOAT, GL_FALSE, sizeof(Vertex),NULL);

glDrawArrays(mode, 0,num_vertices);

glDisableVertexAttribArray(loc_vert);

glDeleteBuffers(1,&vbo);
glDeleteVertexArrays(1,&vao);
This does not fix the problem.

Share this post


Link to post
Share on other sites
Geometrian    1810

I wasn't able to set up a debug context on the Pi since GLEW 1.10 isn't supported by default and setting it up would be a pain. However, I can check glGetError, which returns 0 right before glDrawArrays(...), as it should.

Share this post


Link to post
Share on other sites
dave j    681
&nbsp;

Hi,

I'm trying to draw simple things with OpenGL ES on a Raspberry Pi.

I created a context through the X system and the glx_create_context_es2_profile extension. This resulted in what I hope is an OpenGL ES 2.0 context (the testing functions gave weird values), but it seems to work for some things (e.g., it gave salient feedback on a shader, which it successfully compiled).


The Raspberry Pi doesn't, currently, support it's hardware OpenGL ES through GLX. You've probably got a Mesa context.

You have to get the GL context using the Broadcom and EGL APIs. Look at the example in /opt/vc/src/hello_pi/hello_triangle2.

Share this post


Link to post
Share on other sites
Geometrian    1810
That is extremely unfortunate, but it seems to be correct. See also:

The traditional way (on Linux) is to use the X window system to provide a surface on which the OpenGL/OpenGL ES surface can be rendered. At this moment, the implementation of X for the Raspberry Pi is unable to do this, and so you can’t use X to provide your surface. I am very sure that this support will be added in time, but until then, people wanting to play with this will have to connect up the OpenGL ES side of things to the display by another method.


I'll see about setting up a context with those APIs. Thanks,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
    • By Picpenguin
      Hi
      I'm new to learning OpenGL and still learning C. I'm using SDL2, glew, OpenGL 3.3, linmath and stb_image.
      I started following through learnopengl.com and got through it until I had to load models. The problem is, it uses Assimp for loading models. Assimp is C++ and uses things I don't want in my program (boost for example) and C support doesn't seem that good.
      Things like glVertexAttribPointer and shaders are still confusing to me, but I have to start somewhere right?
      I can't seem to find any good loading/rendering tutorials or source code that is simple to use and easy to understand.
      I have tried this for over a week by myself, searching for solutions but so far no luck. With tinyobjloader-c and project that uses it, FantasyGolfSimulator, I was able to actually load the model with plain color (always the same color no matter what I do) on screen and move it around, but cannot figure out how to use textures or use its multiple textures with it.
      I don't ask much: I just want to load models with textures in them, maybe have lights affect them (directional spotlight etc). Also, some models have multiple parts and multiple textures in them, how can I handle those?
      Are there solutions anywhere?
      Thank you for your time. Sorry if this is a bit confusing, English isn't my native language
  • Popular Now