Linux, OpenGl, VBO and SDL?

Hi!

I want to use VBOs under Linux/C and found some code samples that use SDL
to call the functions of the openGL extension.

Do you know another way, without SDL? If not, is this the right way to use
it?
It crashes while calling glDrawArrays :frowning:
Any suggestions?

I just put the interesting lines below.

thx
Christiane.

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
//#include “glext.h”

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h> //cpp

#include “…/rawlib/rawFile.h”

#include <SDL.h>
//#include <SDL_opengl.h>

#define GL_ARRAY_BUFFER_ARB 0x8892
#define GL_STATIC_DRAW_ARB 0x88E4

typedef void (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint
buffer);
typedef void (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint
*buffers);
typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
typedef void (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size,
const GLvoid *data, GLenum usage);

// VBO Extension Function Pointers
PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;
// VBO Name Generation Procedure
PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;
// VBO Bind Procedure
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;
// VBO Data Loading Procedure
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL;
// VBO Deletion Procedure

GLuint vertex_VBO;
GLfloat vertex_array[3*(RAW_HEIGHT/2)*(RAW_WIDTH/2)];

void buildVertexArrays(int fieldType)
{
int x,y;
int i=0;

//draw the points
for ( y = 0; y < RAW_HEIGHT/2; y++ )
for (x = 0; x < RAW_WIDTH/2; x++)
{
vertex_array[i++]= x - RAW_WIDTH/4;
switch (fieldType)
{
case ‘A’: vertex_array[i++] = fieldA[y][x];break;
case ‘B’: vertex_array[i++] = fieldB[y][x];break;
case ‘C’: vertex_array[i++] = fieldC[y][x];break;
case ‘D’: vertex_array[i++] = fieldD[y][x];break;
}
vertex_array[i++]= y - RAW_HEIGHT/4;
}
}

void myInit(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT); //???
glPointSize(1.0);

buildVAs(‘A’);
}

void make_VBOs(){
printf(“Uploading Data to the Graphics Card…\n”);fflush(stdout);
// Generate And Bind The Vertex Buffer
glGenBuffersARB( 1, &vertex_VBO );
// Get A Valid Name
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vertex_VBO );
// Bind The Buffer
// Load The Data
glBufferDataARB( GL_ARRAY_BUFFER_ARB,

(RAW_HEIGHT/2)*(RAW_WIDTH/2)3sizeof(GLfloat),

vertex_array, GL_STATIC_DRAW_ARB );

}

void myDisplay(void)
{
int x,y;
double eyeX = 0, eyeY = 0, eyeZ = 0;

glClear(GL_COLOR_BUFFER_BIT);

glLoadIdentity();
//eye x,y,z; center x,y,z; up x,y,z
if (topView)
{eyeX = 0.0; eyeY = CCD_MAX+7000.0; eyeZ = 0.0;}
else
{eyeX = 0.0; eyeY = CCD_MAX/2.0; eyeZ = 7000.0;}
gluLookAt(eyeX - moveX, eyeY - moveY, eyeZ - moveZ, -moveX, CCD_MAX/2.0
-moveY, -moveZ, 0.0, 1.0, 0.0);

//glScalef(1.0, 2.0, 1.0);
glRotatef(1.0rotX,1.0,0.0,0.0);
glRotatef(1.0
rotY,0.0,1.0,0.0);
glRotatef(1.0*rotZ,0.0,0.0,1.0);

…
glEnableClientState( GL_VERTEX_ARRAY );
// Enable Vertex Arrays
glBindBufferARB( GL_ARRAY_BUFFER_ARB, vertex_VBO );
glVertexPointer( 3, GL_FLOAT, 0, NULL );
// Set The Vertex Pointer To The Vertex Buffer
glDrawArrays(GL_POINTS, 0, (RAW_HEIGHT/2)*(RAW_WIDTH/2));

glutSwapBuffers();
glFlush();

}

void myReshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
gluPerspective(40.0, (GLsizei) w/(GLsizei) h, 0.0, 10000.0);
glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
//gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

int main(int argc, char** argv)
{
int retVal;
int VBOSupported;

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1000, 1000);
glutInitWindowPosition(100, 150);
glutCreateWindow(“RawViewer”);
myInit();
int i;
for(i=0;i<3*(RAW_HEIGHT/2)*(RAW_WIDTH/2);i+=3)
printf(“x %f, y %f, z %f\n”, vertex_array[i],

vertex_array[i+1],vertex_array[i+2]);

if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, “SDL konnte nicht initialisiert werden: %s\n”,
SDL_GetError());
exit(1);
}

if (SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1)<0)
{
printf(“Unable to set GL attribute : %s\n”,SDL_GetError());
exit(1);
}
if (SDL_SetVideoMode(1000,1000,0,SDL_OPENGL)==NULL)
{
printf(“Unable to open video mode : %s\n”,SDL_GetError());
exit(1);
}
atexit(SDL_Quit);

VBOSupported = isExtensionSupported( “GL_ARB_vertex_buffer_object” );

if(VBOSupported)
{
// Get Pointers To The GL Functions

  glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)

SDL_GL_GetProcAddress(“glGenBuffersARB”);
glBindBufferARB = (PFNGLBINDBUFFERARBPROC)
SDL_GL_GetProcAddress(“glBindBufferARB”);
glBufferDataARB = (PFNGLBUFFERDATAARBPROC)
SDL_GL_GetProcAddress(“glBufferDataARB”);
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)
SDL_GL_GetProcAddress(“glDeleteBuffersARB”);
make_VBOs();
}

glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);
glutMouseFunc(mouseButtonCallback);
glutMotionFunc(mouseMotionCallback);
glutKeyboardFunc(myKeyboardCallback);
glutSpecialFunc(mySpecialFuncCallback);
glutMainLoop();

exit(0);
}

[snip]

You seem to be very confused. You’re mixing GLUT and SDL in the same
program. Both SDL and GLUT serve the same purpose in this context (namely
setting up an OpenGL window and rendering context for you), so mixing them
is a) pointless and b) likely to cause problems like the one you’ve
encountered.

cu,
Nicolai
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050121/753b2a10/attachment.pgpOn Thursday 20 January 2005 18:01, Christiane U. wrote:

Hi!

I want to use VBOs under Linux/C and found some code samples that use SDL
to call the functions of the openGL extension.

Do you know another way, without SDL? If not, is this the right way to use
it?
It crashes while calling glDrawArrays :frowning:
Any suggestions?

Nicolai Haehnle <prefect_ gmx.net> writes:

Hi!

I want to use VBOs under Linux/C and found some code samples that use SDL
to call the functions of the openGL extension.

Do you know another way, without SDL? If not, is this the right way to use
it?
It crashes while calling glDrawArrays :frowning:
Any suggestions?
[snip]

You seem to be very confused. You’re mixing GLUT and SDL in the same
program. Both SDL and GLUT serve the same purpose in this context (namely
setting up an OpenGL window and rendering context for you), so mixing them
is a) pointless and b) likely to cause problems like the one you’ve
encountered.

cu,
Nicolai


SDL mailing list
SDL libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

:slight_smile: yes, sorry.

I used glut but I had problems with glext.h and wglGetProcAddress (caused a
seg fault) and so on. Then I downloaded the linux/SDL version from here:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=45
and hoped I can use SDL just to load the data to the graphics card.
Ok, no mixing.

I know that’s not a good question for an SDL forum, but do you know if it is
possible to use VBOs without SDL :] ?

Thanx for your help
Christiane.> On Thursday 20 January 2005 18:01, Christiane U. wrote:

Yes, I know, and yes, it’s possible. BTW, GLUT may have a GetProcAddress
function, too. Besides, there are many GLUT demos that use extensions. It
shouldn’t be hard to get documentation on that, so the only question that
remains is: Why not SDL? :stuck_out_tongue:

cu,
Nicolai
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050122/e06df176/attachment.pgpOn Friday 21 January 2005 14:05, Christiane U. wrote:

I know that’s not a good question for an SDL forum, but do you know if it
is possible to use VBOs without SDL :] ?

Nicolai Haehnle <prefect_ gmx.net> writes:

I know that’s not a good question for an SDL forum, but do you know if it
is possible to use VBOs without SDL :] ?

Yes, I know, and yes, it’s possible. BTW, GLUT may have a GetProcAddress
function, too. Besides, there are many GLUT demos that use extensions. It
shouldn’t be hard to get documentation on that, so the only question that
remains is: Why not SDL? :stuck_out_tongue:

cu,
Nicolai

Yes it works :). I found the problem. I just had to call glXGetProcAddressARB
instead of wglGetProcAddress (or SDL_GetProcAdress).
Why not SDL? I didn’t want to switch libraries just because I couldn’t solve the
problem with glut. The reason should be because SDL is better, shouldn’t it :wink: ?

cu,
Christiane.> On Friday 21 January 2005 14:05, Christiane U. wrote:

And it is. ;)> The reason should be because SDL is better, shouldn’t it :wink: ?

–
Casey O’Donnell
RPI STS Department - Graduate Student

http://homepage.mac.com/codonnell/
http://homepage.mac.com/codonnell/wxsync/
http://homepage.mac.com/codonnell/wxblogger/