Sign in to follow this  
Chris528

OpenGL Question about immediate mode

Recommended Posts

Chris528    186

I'm working on a simple opengl test app with sdl 2. I'm using opengl 4.2 and for some reason immediate mode still works after setting the app to use the core profile. Am i doing something wrong? Here's my current code on Pastebin.

Edited by Chris528

Share this post


Link to post
Share on other sites
Arkhyl    626

You have to put thee three SDL_GL_SetAttributes before the context creation for them to be taken into account. Actually you create a GL context with default parameters, which is surely a forward compatible context.

Share this post


Link to post
Share on other sites
marcClintDion    435

You sound like you want it to fail... maybe if you could explain your logic in wanting this this to happen, if this really is what you want. 

 

Is your expectation that a core OpenGL 4.2 profile should fail when legacy code is used?

 

I suspect that the most reliable way to unsure this happens is to prevent the code from compiling to begin with.  You would likely have problems doing this if you are using an extension wrangler.  It's kind of hard to pull apart everything they attach to your program.

 

If, however, you decide to only use gl.h and a glext.h header files for initializing OpenGL, then you have pretty much full control with easy access to functions you want to omit. 

 

Search online for "OpenGL deprecated" then search for those functions and definitions in the above mentioned header files.  Manually delete everything that you do not want to support.  Add only what you do want to use.  What you can't remove you will know not to use.

 

Or you could hope that someone will do this for you seamlessly in the background.  Personally, I'd rather take control of this than leave it in the hands of others.

Share this post


Link to post
Share on other sites
Chris528    186

You have to put thee three SDL_GL_SetAttributes before the context creation for them to be taken into account. Actually you create a GL context with default parameters, which is surely a forward compatible context.

This brings up another question, is the context supposed to be created before or after the creation of the window? It crashes at runtime when I try to create the context first. According to the sdl_video.h header, SDL_GL_SetAttribute should be used before window creation.

Edited by Chris528

Share this post


Link to post
Share on other sites
Chris528    186

You sound like you want it to fail... maybe if you could explain your logic in wanting this this to happen, if this really is what you want.

 

I was just curious why my app still worked with immediate mode, when I thought immediate mode was dropped sometime after version 3.0. Was it working because I set the version and the core profile after creating the context? when I added that stuff before the creation of the window, the screen just showed up as black. Does that mean its working as intended now and is no longer registering the immediate mode stuff?

Edited by Chris528

Share this post


Link to post
Share on other sites
Brother Bob    10344

A quick look at some of the many tutorials widely available via your favorite search engine suggests that the call order (whether recommended or required, I don't know) is SetAttribute, CreateWindow and then CreateContext. In any case, as far as OpenGL goes and not related to SDL specifically, the window has to be created before the context.

Share this post


Link to post
Share on other sites
marcClintDion    435
I was just curious why my app still worked with immediate mode, when I thought immediate mode was dropped sometime after version 3.0.

 

It's always been my experience that if the code is in any way valid, nVidia, ATI, and Intel drivers will run it and even correct errors to the best of their abilities.  One of the design goals of OpenGL has always been backwards compatibility. 

 

Here is a page with people that are attempting to do what you are doing.  There are several extensions available to help you with this.

 

http://stackoverflow.com/questions/13062149/how-do-i-make-this-simple-opengl-code-works-in-a-lenient-3-3-and-4-2-profile

http://stackoverflow.com/questions/4693017/forcing-opengl-core-profile-only

 

You should consider what you are doing to be experimental with only limited truly real support.  The various video card manufacturers are not required to have fully implemented features in hardware before claiming that they meet the spec.  If the GPU's drivers can run a particular feature on the host CPU then they meet the spec so far as the "law" is concerned. 

 

It could be several years before all the various manufacturers really do have full hardware accelerated support that works consistently on all brands without huge portability issues popping up.  Unless you are interested in a particular 4.0+ feature such as 5 stage tessellation then you are asking for trouble by forcing a profile that has not been out in the wild for very long. 

Most of the example code that you find right now will be full of bugs, it will work on one GPU and not another.

This is likely why Apple appears to be behind the curve with support for these things.  It's often better to wait than to push something that will fail on someone's else's computer simply because that other person has a different driver or GPU installed.

 

If you do want to be a trail-blazer here, then just make sure you are constantly verifying everything you do on as many different GPU's as possible.  Check them all for stability as well as performance benefit. 

Try every possible method and extension to find the ones that work consistently across the board.  I'm not convinced that this is even possible at the current time with the 4.0+ specs.  We still have not seen this happen in the open source community with the 3.0-ish stuff.

 

It can take years for new technology to be decimated through the open source community in a form that is consistent and reliable,  but if you are one of the people who will help to pull this off then I say go for it. 

Just be forewarned and you will be mostly prepared is all I'm saying here.

 

Here is an example of what's going on here on a different thread for some 3.0-ish techniques.  You should expect much worse for what you are going after,4.0+ , but you can also learn from his method.  Just don't be so quick to blame one particular brand.  I have no doubt at all that some other person is having the reverse problem with both these companies.  It's the nature of forging a new path.

 

http://www.gamedev.net/topic/644327-custom-pseudo-instancing-faster-than-real-instancing-on-nvidia-cards/

Share this post


Link to post
Share on other sites
Brother Bob    10344

 


I was just curious why my app still worked with immediate mode, when I thought immediate mode was dropped sometime after version 3.0.

 

It's always been my experience that if the code is in any way valid, nVidia, ATI, and Intel drivers will run it and even correct errors to the best of their abilities.  One of the design goals of OpenGL has always been backwards compatibility. 

Backward compatibility was reset with the release of new version 3.0 API and the core profile, although you can create a compatibility profile up to 3.1 or 3.2, don't remember which, that allows you to run both the pre-3.0 and the post-3.0 APIs at the same time. In 3.3 and forward at least, that is no longer possible.

 

Since he's creating a 4.2 context (or rather, tried to), there is no compatibility with the pre-3.0 era and any such call shall fail.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
  • Popular Now