Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7416073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:25:06+00:00 2026-05-29T07:25:06+00:00

I am currently trying to draw an object using VBOs. In the Cube-Class I

  • 0

I am currently trying to draw an object using VBOs.
In the Cube-Class I came up with to test the functionality of VBOs, I create the VBOs like this:

//Vertex
glGenBuffers(1, &m_bufVertex);
glBindBuffer(GL_ARRAY_BUFFER, m_bufVertex);
glBufferData(GL_ARRAY_BUFFER, 6*4*3*sizeof(GLfloat), vertex_data, GL_STATIC_DRAW);
//TexCoord
glGenBuffers(1, &m_bufTexCoord);
glBindBuffer(GL_ARRAY_BUFFER, m_bufTexCoord);
glBufferData(GL_ARRAY_BUFFER, 6*4*2*sizeof(GLfloat), texcoord_data, GL_STATIC_DRAW);
//Index
glGenBuffers(1,&m_bufIndex);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_bufIndex);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,24*sizeof(GLuint), indices, GL_STATIC_DRAW);

I already double checked if the data is in the buffers e.g. like this (the vertex buffer is binded at that time):

GLfloat* test = (GLfloat *) glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
for (unsigned int i = 0; i < 6*4*3; i++)
    cout << "Value " << i << " = " << test[i] << endl;

So the data is where it is supposed to be, so the problem seems to lie within the Render-Function. The Segmentation-Error happens when glDrawElements() or glDrawArrays() is called.
Here is the code:

glBindTexture(GL_TEXTURE_2D, m_texture);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// some translation, currently fixed, just testing code
glTranslatef(0.0f, 0.0f, -200.0f);
glRotatef(30.f, 1.f, 0.f, 0.f);
glRotatef(30.f, 0.f, 1.f, 0.f);
glRotatef(30.f, 0.f, 0.f, 1.f);
// enable client states
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// set pointers
glBindBuffer(GL_ARRAY_BUFFER, m_bufVertex);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_bufTexCoord);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_bufIndex);
// just error check to see if something went wrong previously
GLenum err = glGetError();
if (GL_NO_ERROR != err)
    cout << "GL: " << err << " - " << gluErrorString(err) << endl;
glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, 0);
// disable state and pop matrix
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPopMatrix();

I assume I am using the pointers not right or glDrawElements(), but I don’t know what.
Some more informations:
The code is compiled on MacOSX Lion (OpenGL2.1) using the GNU-toolchain and GLEW.

EDIT:

GLfloat vertex_data[6*4*3] = {-m_fSize, -m_fSize, -m_fSize,
                       -m_fSize,  m_fSize, -m_fSize,
                        m_fSize,  m_fSize, -m_fSize,
                        m_fSize, -m_fSize, -m_fSize,
                        -m_fSize, -m_fSize, m_fSize,
                        -m_fSize,  m_fSize, m_fSize,
                         m_fSize,  m_fSize, m_fSize,
                         m_fSize, -m_fSize, m_fSize,
                       -m_fSize, -m_fSize, -m_fSize,
                       -m_fSize,  m_fSize, -m_fSize,
                       -m_fSize,  m_fSize,  m_fSize,
                       -m_fSize, -m_fSize,  m_fSize,
                        m_fSize, -m_fSize, -m_fSize,
                        m_fSize,  m_fSize, -m_fSize,
                        m_fSize,  m_fSize,  m_fSize,
                        m_fSize, -m_fSize,  m_fSize,
                       -m_fSize, -m_fSize,  m_fSize,
                       -m_fSize, -m_fSize, -m_fSize,
                        m_fSize, -m_fSize, -m_fSize,
                        m_fSize, -m_fSize,  m_fSize,
                        -m_fSize, m_fSize,  m_fSize,
                        -m_fSize, m_fSize, -m_fSize,
                         m_fSize, m_fSize, -m_fSize,
                        m_fSize, m_fSize,  m_fSize};
 GLfloat texcoord_data[6*4*2] = {0, 0, 0, 1, 1, 1, 1, 
                                0, 0, 0, 0, 1, 1, 1, 
                                1, 0, 0, 0, 0, 1, 1, 
                                1, 1, 0, 0, 0, 0, 1,
                                1, 1, 1, 0, 0, 1, 0, 
                                0, 1, 0, 1, 1, 0, 1,
                                0, 0, 1, 0, 1, 1};
GLuint indices[24] = {0,1,2,3,
                     4,5,6,7,
                     8,9,10,11,
                     12,13,14,15,
                     16,17,18,19,
                     20,21,22,23};

I know am defining every vertex instead of just 8…

EDIT2:
The makefile:

OUT = bin/test
CC = g++
INCDIR = inc
OBJDIR = obj
SRCDIR = src
INC = -I$(INCDIR) -I/opt/local/include
LIBS = -L/opt/local/lib -lGLEW -lsfml-graphics -lsfml-window -lsfml-system -framework AGL -framework OpenGL -framework Foundation

_OBJS = Main.o \
    Timer.o \
    Cube.o \
    chrono.o process_cpu_clocks.o thread_clock.o error_code.o

OBJS = $(patsubst %,$(OBJDIR)/%,$(_OBJS))

$(OBJDIR)/%.o: $(SRCDIR)/%.cpp 
$(CC) -c $(INC) -o $@ $< $(CFLAGS) 


$(OUT): $(OBJS)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
strip $(OUT)

clean:
rm -f $(OBJDIR)/*.o $(OUT)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:25:06+00:00Added an answer on May 29, 2026 at 7:25 am

    I had the exact same problem. The problem is that SFML internally uses
    glEnableClientState(GL_COLOR_ARRAY) and
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    so you need to disable those if you don’t use them yourself.

    Or you could use sf::Window instead of sf::RenderWindow, since it doesn’t set any OpenGL state internally, which I chose to do.

    Post on the SFML forum with this exact problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to draw shapes with 2D Arrays. In my class there is
Like many others, I am trying to draw 3D objects (using GLSurfaceView) on camera
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying out db4o (the java version) and I pretty much like what
I'm currently trying to build a personal website to create a presence on the
I'm trying to model an object described in a WRL (VRML) file using OpenGL.
I am drawing one object using multi-texturing. That comes fine but when I draw
I'm trying to use the Sprite Class in Microsoft.DirectX.Direct3D to draw some sprites to
This is yet another Unit Testing question. I'm trying to draw knowledge from a
I'm trying to make a program that will draw lines over a picturebox using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.