SFML community forums

Help => Window => Topic started by: Fierce_Dutch on December 07, 2010, 07:14:50 am

Title: OpenGL not Working
Post by: Fierce_Dutch on December 07, 2010, 07:14:50 am
Here is my code :

Code: [Select]
#include <SFML\Graphics.hpp>
#include <SFML\OpenGL.hpp>


GLfloat rquad;

void Draw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glShadeModel(GL_SMOOTH);
   glLoadIdentity(); // Reset The Current Modelview Matrix
   glPushMatrix();
glRotatef(rquad,0.0,1.0,0);
glBegin(GL_QUADS);
glColor3f(2.0, 0.0, 0.0);  //

glVertex3f(0.30, 0.30, 0.0);
glVertex3f(0.30, 0.70, 0.0);
glVertex3f(0.70, 0.70, 0.0);
glVertex3f(0.70, 0.30, 0.0);

glColor3f(255.0, 0.0, 0.0); //

glVertex3f(0.70, 0.30, 0.3);
glVertex3f(0.70, 0.70, 0.3);
glVertex3f(0.70, 0.70, 0.0);
glVertex3f(0.70, 0.30, 0.0);

glColor3f(0.0, 255.0, 0.0); //

glVertex3f(0.30, 0.70, 0.3);
glVertex3f(0.30, 0.30, 0.3);
glVertex3f(0.70, 0.30, 0.3);
glVertex3f(0.70, 0.70, 0.3);

glColor3f(0.0, 0.0, 255.0); //

glVertex3f(0.30, 0.70, 0.0);
glVertex3f(0.30, 0.30, 0.0);
glVertex3f(0.30, 0.30, 0.3);
glVertex3f(0.30, 0.70, 0.3);

glColor3f(1.0,1.0,1.0);  //

glVertex3f(0.30, 0.70, 0.0);
glVertex3f(0.70, 0.70, 0.0);
glVertex3f(0.30, 0.70, 0.3);
glVertex3f(0.70, 0.70, 0.3);

glVertex3f(0.30, 0.30, 0.0);
glVertex3f(0.70, 0.30, 0.0);
glVertex3f(0.30, 0.30, 0.3);
glVertex3f(0.70, 0.30, 0.3);


glEnd();
glPopMatrix();
rquad+=-0.5;
glFlush();
}

void Initialize() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}

int main(int iArgc, char** cppArgv) {
sf::Window App(sf::VideoMode(800,800,8), "OpengGL Test");
Initialize();
while(App.IsOpened())
{
glClear(GL_COLOR_BUFFER_BIT);
Draw();
App.Display();
}
return 0;
}


Ok Well I have gotten rid of those errors by creating a new project and trying to do all of this again but now window doesnt display. It doesnt pop up at all...
[/code]
Title: OpenGL not Working
Post by: Laurent on December 07, 2010, 07:57:44 am
You must link to sfml-window.lib and opengl32.lib.
Title: OpenGL not Working
Post by: Fierce_Dutch on December 08, 2010, 06:47:12 pm
Quote from: "Laurent"
You must link to sfml-window.lib and opengl32.lib.


I did. and I also defined sfml static. Still doesnt work...

BTW edited for graphics lib not window lib.
Title: OpenGL not Working
Post by: Hiura on December 08, 2010, 10:25:08 pm
it seems you need both graphics and window.
Title: OpenGL not Working
Post by: Fierce_Dutch on December 09, 2010, 12:42:33 am
Quote from: "Hiura"
it seems you need both graphics and window.


I have linked and included both, still no luck
Title: OpenGL not Working
Post by: Laurent on December 09, 2010, 08:06:41 am
How did you link them?
Title: OpenGL not Working
Post by: Fierce_Dutch on December 10, 2010, 02:35:14 am
Quote from: "Laurent"
How did you link them?


I have linked all the sfml stuff, Opengl32.lib, and glu32.lib with the additional dependencies linker in vc++. I defined SFML_STATIC. Also I have put the sfml headers and the gl folder with the gl and glu headers in the include folder in the vc folder in the visual c++ folder. Also I included the libs in there for sfml and glu and opengl

BTW can you please help me do this before the weekend because I really want to devote that weekend to learning Opengl.

Btw I think it is a bit hard to talk to each other since we are across the world from eachother.. (US)
Title: OpenGL not Working
Post by: Laurent on December 10, 2010, 07:18:07 am
Quote
I defined SFML_STATIC

What revision of SFML 2 are you using? How did you define SFML_STATIC?
Title: OpenGL not Working
Post by: Relic on December 10, 2010, 07:29:25 am
Quote
Laurent wrote:
You must link to sfml-window.lib and opengl32.lib.

Shouldn't it be sfml-window-S.lib if he uses SFML_STATIC?
Title: OpenGL not Working
Post by: Laurent on December 10, 2010, 10:39:37 am
Quote
Shouldn't it be sfml-window-S.lib if he uses SFML_STATIC?

Yes. It didn't mention it in his first message.
Title: OpenGL not Working
Post by: Fierce_Dutch on December 10, 2010, 04:24:29 pm
Quote from: "Laurent"
Quote
I defined SFML_STATIC

What revision of SFML 2 are you using? How did you define SFML_STATIC?


In the preprocessor directives... I am using the libraries statically...
Title: OpenGL not Working
Post by: Laurent on December 10, 2010, 04:36:31 pm
When did you download SFML 2?
Title: OpenGL not Working
Post by: Fierce_Dutch on December 11, 2010, 12:03:53 am
Quote from: "Laurent"
When did you download SFML 2?


Like two days ago I updated my repository again and rebuilt it. I rebuilt it correctly, dont worry.

Also Please check the first post.
Title: OpenGL not Working
Post by: foofel on December 18, 2010, 02:44:13 am
Hey, i got a similar issue since the Catalyst driver version 10.10 (10.09 worked). I have the problem with SFML 1.6 and 2.0 using 32 or 64 bit doesn't change anything. I am not sure where the problem started, but it hangs at:

Code: [Select]

myGLContext = wglCreateContext(myDeviceContext);


on WindowImplWin32.cpp line 629 (or close, tried something). And it literally hangs, there is no error message or anything the call just doesn't return, like its blocking. Downgrading Catalyst also works, but everything else is working fine (e.g Games. Even the nehe tutorials work. Tested lesson2 and 3). Cause the newest OpenCL SDK needs the newest driver version i can no longer use the 10.09 version... hopefully somebody finda a fix ;)

I am using Win7 64 Bit and VS 2010.
Title: OpenGL not Working
Post by: Laurent on December 18, 2010, 08:50:04 am
Ok ok, I get it. You'll have to wait until the global exit crash is fixed (this is the same kind of problem).
Title: OpenGL not Working
Post by: foofel on December 18, 2010, 03:04:26 pm
Quote from: "Laurent"
Ok ok, I get it. You'll have to wait until the global exit crash is fixed (this is the same kind of problem).


Damn, is there a workaround or something? :)
Title: OpenGL not Working
Post by: Laurent on December 18, 2010, 03:40:12 pm
Quote
Damn, is there a workaround or something?

Using static libraries ;)
Title: OpenGL not Working
Post by: foofel on December 18, 2010, 03:56:11 pm
Quote from: "Laurent"
Quote
Damn, is there a workaround or something?

Using static libraries ;)


Works, thanks :)

[edit] But could you try to explain what happens, so the dll version doesn't work?
Title: OpenGL not Working
Post by: Laurent on December 18, 2010, 04:23:27 pm
Quote
But could you try to explain what happens, so the dll version doesn't work?

I have a global OpenGL context in SFML, which is created at global startup (before main()) and destroyed at global exit (after main()). This is not very clean programming practice, but it's so convenient.
For an unknown reason, when I do this from a DLL it causes a crash in the ATI OpenGL driver. So there's no easy bug, I need to remove this global context but this means adding a manual SFML init() and cleanup(), and I really don't like it.
Title: OpenGL not Working
Post by: Groogy on December 18, 2010, 04:28:16 pm
Quote from: "Laurent"
Quote
But could you try to explain what happens, so the dll version doesn't work?

I have a global OpenGL context in SFML, which is created at global startup (before main()) and destroyed at global exit (after main()). This is not very clean programming practice, but it's so convenient.
For an unknown reason, when I do this from a DLL it causes a crash in the ATI OpenGL driver. So there's no easy bug, I need to remove this global context but this means adding a manual SFML init() and cleanup(), and I really don't like it.


Could have been the problem I experienced before?
Anyway you could have support for both? And then let us have a SFML object se we can write something like:
Code: [Select]
#define SFML_NO_GLOBAL
#include <SFML/System.hpp>

int main()
{
    sf::SFML *sfml = new sf::SFML(/* Maybe settings here if wanted? */);
    delete sfml;
    return 0;
}


I just used new and delete to show that we manually decide when we initiate and when we cleanup.
Title: OpenGL not Working
Post by: Laurent on December 18, 2010, 05:31:55 pm
Quote
Anyway you could have support for both?

No. Why should I do that?

Quote
And then let us have a SFML object

Don't know yet.
Title: OpenGL not Working
Post by: Groogy on December 18, 2010, 06:43:50 pm
Quote from: "Laurent"
Quote
Anyway you could have support for both?

No. Why should I do that?


Don't know just spewing out ideas :P
Title: OpenGL not Working
Post by: Nexus on December 18, 2010, 07:40:29 pm
If this case should ever become relevant, I think the most appropriate version would be a RAII wrapper around Init() and Cleanup(), so that there is at least only one line.
Code: [Select]
int main()
{
    sf::GlobalContext context; // Automatic Init()
    ... // Do SFML stuff here
    ...
} // Automatic Cleanup() at end of scope
Title: OpenGL not Working
Post by: Laurent on December 18, 2010, 07:43:42 pm
Of course :)
Title: OpenGL not Working
Post by: Groogy on December 18, 2010, 07:47:56 pm
Quote from: "Nexus"
If this case should ever become relevant, I think the most appropriate version would be a RAII wrapper around Init() and Cleanup(), so that there is at least only one line.
Code: [Select]
int main()
{
    sf::GlobalContext context; // Automatic Init()
    ... // Do SFML stuff here
    ...
} // Automatic Cleanup() at end of scope


That's what I meant but I used new and delete to show I meant the constructor and destructor, maybe it wasn't as apparent as I thought.
Title: OpenGL not Working
Post by: angelmxc on December 19, 2010, 11:42:24 am
Same problem, ati driver 10.09 works, fail with 10.10, 10.11, 10.12, works fine on Ubuntu 10.10 using HD5850, I'm using temporarily MesaGL using software processing on Windows 7-64, i compiled MesaGL version 7.8.2, you can download libs from  HERE (http://rapidshare.com/files/438158885/MesaGL_7.8.2.zip), just copy the libraries in .exe's directory and run your exe.
Title: OpenGL not Working
Post by: foofel on December 20, 2010, 05:50:02 pm
Nice :)