SDL and OpenGL - How do I draw?

Hello everybody!

I have quite recently begun coding using SDL and OpenGL, but I’m at a loss
here… I have set up a small testing-program, but when I start drawing to
the window using OpenGL commands followed by SDL_GL_SwapBuffers();, nothing
happens. The window just stays black…
I dont have that much experience in programming, so it is possible that
something small has slipped my mind.
Here are links to the different source files:
http://uploads.theswedishconspiracy.com/stuff/test.cpp
http://uploads.theswedishconspiracy.com/stuff/init.h
http://uploads.theswedishconspiracy.com/stuff/init.cpp

Can anyone help me?

Thanks beforehand.
/Chris

Chris Rajula ha scritto:

Here are links to the different source files:
http://uploads.theswedishconspiracy.com/stuff/test.cpp
http://uploads.theswedishconspiracy.com/stuff/init.h
http://uploads.theswedishconspiracy.com/stuff/init.cpp

I don’t see any drawing code in your files…

:-?–
SkunkGuru

Well no, I left that part out, but I used this code:

glColor3f(0.7f, 1.0f, 0.3f);
glBegin(GL_TRIANGLES);
    glVertex3f(1.0f, -1.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);
    glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();On 12/30/06, SkunkGuru <skunkguru at gmail.com> wrote:

Chris Rajula ha scritto:

Here are links to the different source files:
http://uploads.theswedishconspiracy.com/stuff/test.cpp
http://uploads.theswedishconspiracy.com/stuff/init.h
http://uploads.theswedishconspiracy.com/stuff/init.cpp

I don’t see any drawing code in your files…

:-?


SkunkGuru


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

Hi,

What do you use?

Mac OSX? or Windows?

I don’t know about Windows, but in sdl homepage you can find in the
downloads section a file with a lot of examples:

http://www.libsdl.org/release/SDL-devel-1.2.11-extras.dmg

There is an opengl application template.

You can start with that template to make your own application without
invest too much time.

Even if you use windows, i think you have just to take one file out, the
one related with cocoa.

Nuno

Chris Rajula escreveu:> Hello everybody!

I have quite recently begun coding using SDL and OpenGL, but I’m at a
loss here… I have set up a small testing-program, but when I start
drawing to the window using OpenGL commands followed by
SDL_GL_SwapBuffers();, nothing happens. The window just stays | black…
I dont have that much experience in programming, so it is possible
that something small has slipped my mind.
Here are links to the different source files:
http://uploads.theswedishconspiracy.com/stuff/test.cpp
http://uploads.theswedishconspiracy.com/stuff/init.h
http://uploads.theswedishconspiracy.com/stuff/init.cpp

Can anyone help me?

Thanks beforehand.
/Chris


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

Well no, I left that part out, but I used this code:

glColor3f(0.7f, 1.0f, 0.3f);

This first line should probably be inside the glBegin/glEnd block, or
the behavior is undefined. (I think most drivers will just ignore
it.)

glBegin(GL_TRIANGLES);
    glVertex3f(1.0f, -1.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);
    glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Saturday 30 December 2006 14:38, Chris Rajula wrote:

Oh, I use Gentoo Linux…On 12/30/06, David Olofson wrote:

On Saturday 30 December 2006 14:38, Chris Rajula wrote:

Well no, I left that part out, but I used this code:

glColor3f(0.7f, 1.0f, 0.3f);

This first line should probably be inside the glBegin/glEnd block, or
the behavior is undefined. (I think most drivers will just ignore
it.)

glBegin(GL_TRIANGLES);
    glVertex3f(1.0f, -1.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);
    glVertex3f(0.0f, 1.0f, 0.0f);
glEnd();

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


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

Hey David, putting the OpenGL color-command inside the drawing function
fixed the problem, can’t thank you enough.

/ChrisOn 12/30/06, Chris Rajula <@Chris_Rajula> wrote:

Oh, I use Gentoo Linux…

On 12/30/06, David Olofson wrote:

On Saturday 30 December 2006 14:38, Chris Rajula wrote:

Well no, I left that part out, but I used this code:

glColor3f(0.7f, 1.0f, 0.3f);

This first line should probably be inside the glBegin/glEnd block, or
the behavior is undefined. (I think most drivers will just ignore
it.)

glBegin(GL_TRIANGLES);
    glVertex3f(1.0f, -1.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f, 0.0f);
    glVertex3f( 0.0f, 1.0f, 0.0f);
glEnd();

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --’


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

Well no, I left that part out, but I used this code:

glColor3f(0.7f, 1.0f, 0.3f);

This first line should probably be inside the glBegin/glEnd block, or
the behavior is undefined. (I think most drivers will just ignore
it.)

No, you can set the current color at any time, both “anywhere” as any
normal gl context property, and also within glBegin/glEnd.

// MartinOn Sat, 30 Dec 2006, David Olofson wrote:

On Saturday 30 December 2006 14:38, Chris Rajula wrote:

Well no, I left that part out, but I used this code:

glColor3f(0.7f, 1.0f, 0.3f);

This first line should probably be inside the glBegin/glEnd block,
or
the behavior is undefined. (I think most drivers will just ignore
it.)

No, you can set the current color at any time, both “anywhere” as
any normal gl context property, and also within glBegin/glEnd.

Yeah, I know the official documentation suggests it’s supposed to work
that way, but implementations tend to disagree. :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Saturday 30 December 2006 15:29, Martin Storsj? wrote:

On Sat, 30 Dec 2006, David Olofson wrote:

On Saturday 30 December 2006 14:38, Chris Rajula wrote:

Chris Rajula wrote:

Hello everybody!

I have quite recently begun coding using SDL and OpenGL, but I’m at a loss
here… I have set up a small testing-program, but when I start drawing to
the window using OpenGL commands followed by SDL_GL_SwapBuffers();,
nothing happens. The window just stays black…
I dont have that much experience in programming, so it is possible that
something small has slipped my mind.
Here are links to the different source files:
http://uploads.theswedishconspiracy.com/stuff/test.cpp
http://uploads.theswedishconspiracy.com/stuff/init.h
http://uploads.theswedishconspiracy.com/stuff/init.cpp

Can anyone help me?

Thanks beforehand.
/Chris
I faced a similar problem not long ago. Make sure you use the result of
sdl-config --cflags during build time and that you properly include SDL by
doing :
#include <SDL.h>
and NOT
#include <SDL/SDL.h>

I was debugging a small opengl app that worked for the one who wrote it and
failed on my computer with a black window like you.

Well no, I left that part out, but I used this code:

glColor3f(0.7f, 1.0f, 0.3f);

This first line should probably be inside the glBegin/glEnd block,
or
the behavior is undefined. (I think most drivers will just ignore
it.)

No, you can set the current color at any time, both “anywhere” as
any normal gl context property, and also within glBegin/glEnd.

Yeah, I know the official documentation suggests it’s supposed to work
that way, but implementations tend to disagree. :slight_smile:

Yeah, that situation isn’t really rare. But luckily that has very seldom
been the case on GL, which at least in my experience seems to match specs
and reality quite well. (Perhaps I’ve just happened to have good drivers?)

But in the case with glColor, I’m pretty sure I’ve used it outside of
glBegin/glEnd in a few places and don’t recall having problems with that.

After doing some quick testing, it sure seems to work as intended, too.
(At least on both implementations I tested on, but I guess that’s implied
by “quick” testing.) :slight_smile: Setting glColor before drawing some buffers using
glDrawElements does update the color, as it should. But if using textures,
glColor doesn’t affect anything, of course, unless the material color is
set to track the current color. Also that according to the manual.

// MartinOn Sat, 30 Dec 2006, David Olofson wrote:

On Saturday 30 December 2006 15:29, Martin Storsj? wrote:

On Sat, 30 Dec 2006, David Olofson wrote:

On Saturday 30 December 2006 14:38, Chris Rajula wrote:

Hello Christophe,

Saturday, December 30, 2006, 2:58:12 PM, you wrote:

I faced a similar problem not long ago. Make sure you use the result of
sdl-config --cflags during build time and that you properly include SDL by
doing :
#include <SDL.h>
and NOT
#include <SDL/SDL.h>

Unless you are using OS X and are using SDL.framework - in that case,
you MUST use <SDL/SDL.h> or Xcode won’t find the header.–
Best regards,
Peter mailto:@Peter_Mulholland

Peter Mulholland wrote:

Hello Christophe,

Saturday, December 30, 2006, 2:58:12 PM, you wrote:

I faced a similar problem not long ago. Make sure you use the result of
sdl-config --cflags during build time and that you properly include SDL
by doing :
#include <SDL.h>
and NOT
#include <SDL/SDL.h>

Unless you are using OS X and are using SDL.framework - in that case,
you MUST use <SDL/SDL.h> or Xcode won’t find the header.

What use is sdl-config for then?

Hello Christophe,

Saturday, December 30, 2006, 4:10:07 PM, you wrote:

What use is sdl-config for then?

For UNIX-style builds. Xcode (and Visual C++) does not use configure
scripts.–
Best regards,
Peter mailto:@Peter_Mulholland

Peter Mulholland wrote:

Hello Christophe,

Saturday, December 30, 2006, 4:10:07 PM, you wrote:

What use is sdl-config for then?

For UNIX-style builds. Xcode (and Visual C++) does not use configure
scripts.

And I though it was possible to write portable code with SDL without using
#ifdef everywhere :confused:

Hello Christophe,

Saturday, December 30, 2006, 4:35:44 PM, you wrote:

And I though it was possible to write portable code with SDL without using
#ifdef everywhere :confused:

You can bodge it by adding the path to the Headers folder inside
SDL.framework to the compilers header search path… so it is possible.–
Best regards,
Peter mailto:@Peter_Mulholland