iDevGames Forums

Full Version: OpenGL glDrawArrays not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I'm trying to render some pixels on screen using glDrawArrays like this:

const GLbyte Points[] = {
       10, 10,
      150, 110,
      110, 150,
      150, 150,

// this goes before the program loop

// this goes in my programn loop
glVertexPointer(2, GL_UNSIGNED_BYTE, 0, Points);
glDrawArrays(GL_POINTS, 0, 3);

The problem is that on runtime the program crashes.
Does anyone know how to make it work?
Given the excerpt of your code you've posted, you're missing calls to (at least) glEnableClientState( GL_VERTEX_ARRAY ) and glColorPointer; additionally, man glVertexPointer reports that that function does not support GL_UNSIGNED_BYTE.
Thank you, it works now.

Is there a way to draw a bitmap , without making a vertex array with all the positions of all the points?
(Dec 16, 2012 07:35 AM)dotbianry Wrote: [ -> ]Is there a way to draw a bitmap , without making a vertex array with all the positions of all the points?

Read the documentation/a few tutorials on the topic of texture mapping Wink
I didn't found anything helpful on texture mapping related to glVertexPointer.
Instead I made some loops to fill an array with all the coordonates of all the points but glDrawArrays doesn't draw it right.

Here's how I'm filling the point coordonate array:
int myclk=0,myclkh=0;
for (int ii=0;ii<786432*2  ;ii+=2 ){
     if(myclk == 1024){ myclk = 0;myclkh++;}
     loc[ii] =myclk;
     loc[ii+1] =  myclkh;

Is there any other solution to this?

I found what the problem was, I wasn't filling the color array properly
(Dec 18, 2012 12:44 PM)dotbianry Wrote: [ -> ]I didn't found anything helpful on texture mapping related to glVertexPointer.

Really? The first result for searching for OpenGL ES texture mapping tutorial seems to be an adequate introduction to texture mapping – it is for iOS (and I think I remember from another thread that you're using Windows), but almost all of the source code in the tutorial is still relevant to cross-platform OpenGL ES...
I have some problems getting the texture mapped on a quad.The program crashes.

My setup is like this:

GLfloat texture[] = {0,0, 1,0, 1,1, 0,1};
GLint box[] = {

// before main loop

GLuint      tex[1];
glGenTextures(1, &tex[0]);
glBindTexture(GL_TEXTURE_2D, tex[0]);

// in loop
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, video);
glVertexPointer(2, GL_INT, 0,box);
glTexCoordPointer(2, GL_FLOAT, 0, texture);

"video" is the array with RGB values of an image
Looks like you're enabling GL_COLOR_ARRAY, but not calling glColorPointer before drawing. For each array that's enabled, whatever value the pointer is set to will be dereferenced, and if you haven't specified one it'll most likely crash.
Also, you want to load the texture (by calling glTexImage2D) only when you create the texture. In other words, gen, bind, teximage, then loop. The only reason you would want to do that is if you are changing the pixels of the texture every frame on the CPU too.
I removed glColorPointer and now it doesn't crash anymore.Now I'm getting a blank white screen,is there anything else to be done for the texture to show up?
And yes the pixels of the texture will change every frame.

I've put this after glBindTexture:
and this after glEnable(GL_TEXTURE_2D);
now the texture appears but I'm getting a really low frame rate
(Dec 20, 2012 04:06 AM)dotbianry Wrote: [ -> ]And yes the pixels of the texture will change every frame.

Could you elaborate on what it is you're trying to achieve?

If you're trying to show an animation, I'd suggest you combine the multiple frames of the animation into a texture (rather than create a texture for every frame of the animation or, worse, change the texture data every frame), a technique known as using a texture atlas.
I'm trying to make a 3D engine with software rendering.
From OpenGL I only need to send the frame , rendered offscreen to the video memory,and I'm hoping the transfer is fast enough to achieve a playable frame rate.
In that case you'll want to try using glTexSubImage() instead. It's supposed to be faster than creating a new texture object using glTexImage2D(), but don't quote me on it. That might not be true anymore for full texture refreshes.
Reference URL's