Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Issues with window initializing using sf::ContextSettings  (Read 6081 times)

0 Members and 2 Guests are viewing this topic.

42yeah

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Issues with window initializing using sf::ContextSettings
« on: March 03, 2018, 12:51:45 pm »
Hi! I'm quite a newbie to sfml, and here's what I got when I am trying to initialize a sf::RenderWindow with an sf::ContextSettings:

Error. Unable to create the context. Retrying without shared context.
Warning. New context created without shared context.
 

 :'(
Also the triangle I want is not displayed on the screen...

So here's the ContextSettings:
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.antialiasingLevel = 4;
settings.majorVersion = 3;
settings.minorVersion = 3;
settings.attributeFlags = sf::ContextSettings::Core;
 

And here's the complete code, if you are interested:
(click to show/hide)

Thanks a HUGE LOT for your help!!!
I'm using macOS High Sierra.
 :)

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Issues with window initializing using sf::ContextSettings
« Reply #1 on: March 03, 2018, 01:21:54 pm »
I just skimmed over your opengl code and it looks fine so here are some guesses:

1) sf::RenderWindow does alter the state of the context after creation, so try to call window.resetGLStates() after the creation of the window.

2) Try to use a sf::Window instead of the sf::RenderWindow, since you use a 3.3 core context the graphics module of SFML won't work anyways. The sf::Window won't touch your contenxt  ;)

3) Shader code correct?


AlexAUT


42yeah

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Issues with window initializing using sf::ContextSettings
« Reply #2 on: March 03, 2018, 02:17:48 pm »
I just skimmed over your opengl code and it looks fine so here are some guesses:

1) sf::RenderWindow does alter the state of the context after creation, so try to call window.resetGLStates() after the creation of the window.

2) Try to use a sf::Window instead of the sf::RenderWindow, since you use a 3.3 core context the graphics module of SFML won't work anyways. The sf::Window won't touch your contenxt  ;)

3) Shader code correct?


AlexAUT

Hey AlexAUT! I tried all your suggestions but none of them works  :'(
Here's my shader & program output:
Vertex Shader rc: 1
Vertex Shader:
Fragment Shader rc: 1
Fragment Shader:
Prrogram rc: 1
Program:
 
The vertex shader rc is glGetShaderiv and vertex shader is glGetShaderInfoLog. So the shaders should be working correctly.

Here's the shader code if you want:

vertex shader:
#version 330 core

layout (location = 0) in vec3 aPos;

void main() {
    gl_Position = vec4(aPos.xyz, 1.0);
}
 

fragment shader:
#version 330 core

out vec4 color;

void main() {
    color = vec4(0.1, 0.2, 0.3, 1.0);
}
 

Thanks a lot!  :)

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Issues with window initializing using sf::ContextSettings
« Reply #3 on: March 03, 2018, 11:18:27 pm »
You forgot to "bind"/use the shader  ;D

prog = ...;
glUseProgram(prog);

Some hints for the future:

Surround your opengl calls with glGetError() you could have a look at my error handling
https://github.com/AlexAUT/aw/blob/master/include/aw/graphics/core/opengl.hpp#L31
https://github.com/AlexAUT/aw/blob/master/src/aw/graphics/core/opengl.cpp#L20

basically all my opengl calls look like:
GL_CHECK(glClear(...));
and when an error occurs an exception is thrown.

And have a look at some opengl debug tools. I can highly recommend this one. It has a nice GUI where you can jump between frames and have a look at the context state (active shaders / textures / framebuffers...) at every opengl call  :D


AlexAUT
« Last Edit: March 04, 2018, 10:32:40 am by AlexAUT »

42yeah

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Issues with window initializing using sf::ContextSettings
« Reply #4 on: March 05, 2018, 04:46:40 pm »
You forgot to "bind"/use the shader  ;D

prog = ...;
glUseProgram(prog);

Some hints for the future:

Surround your opengl calls with glGetError() you could have a look at my error handling
https://github.com/AlexAUT/aw/blob/master/include/aw/graphics/core/opengl.hpp#L31
https://github.com/AlexAUT/aw/blob/master/src/aw/graphics/core/opengl.cpp#L20

basically all my opengl calls look like:
GL_CHECK(glClear(...));
and when an error occurs an exception is thrown.

And have a look at some opengl debug tools. I can highly recommend this one. It has a nice GUI where you can jump between frames and have a look at the context state (active shaders / textures / framebuffers...) at every opengl call  :D


AlexAUT
AlexAUT, you're cool!
I can't mess around my mac now since i am in university again :'(. However, i will try that as soon as I can. Thanks!!

通过我的 XT1650-05 上的 Tapatalk发言


 

anything