I am trying to install opengl 4.5 but I don't know what to download, is there any links that may help me? here is my code.
#version 450 core
void main(void)
{
gl_Position = vec4(0.0, 0.0, 0.5, 1.0);
} I am trying to install opengl 4.5 but I don't know what to download, is there any links that may help me? here is my code.
#version 450 core
void main(void)
{
gl_Position = vec4(0.0, 0.0, 0.5, 1.0);
} That has nothing to do with OpenGl 4.5. It is just a very primitive vertex shader that sets a fixed position to every vertex in the call (which doesn't really make much sense).
This (for example texture handling) is opengl 4.5 (assign a single channel texture):
// GL_TEXTURE_2D / GL_TEXTURE_RECTANGLE
glCreateTextures( GL_TEXTURE_2D, 1, &m_texture );
// no mip levels
if( B16 == depth ) {
glTextureStorage2D( m_texture, 1, GL_R32F, m_extent.x, m_extent.y );
glTextureSubImage2D( m_texture, 0, // texture and mip level
0, 0, m_extent.x, m_extent.y, // offset and size
GL_RED, GL_FLOAT, m_heightValuesNormalized );
} else {
glTextureStorage2D( m_texture, 1, GL_R8UI, m_extent.x, m_extent.y );
glTextureSubImage2D( m_texture, 0, // texture and mip level
0, 0, m_extent.x, m_extent.y, // offset and size
GL_RED_INTEGER, GL_UNSIGNED_BYTE, heightValues8 );
}
glBindTextureUnit( m_textureUnit, m_texture );
// set the default sampler for the heightmap texture
setDefaultSampler( m_texture, LINEAR_CLAMP ); with some abstraction from my side (the default sampler). The difference to earlier versions one finds in internet tutorials being that one can work with the texture by simply naming it, without having to bind it to a texture binding point. Only the unit must match the sampler uniform unit in the shader.
Get the Red (Programming Guide) and the Blue (SuperBible) book and work with them ! Really. Everything is explained in there. Well, almost :-))
Edit: don't use it in your code ! It won't run. It's just a demo to point out a very special case copied out of a loader routine.
I got this code from the OpenGL superbible 7th ed. I just don't know how to link the opengl 4.5 into visual studio 2017
glew (or any other loader, like glad, other ?) There is nothing special.
Just use it. You have posted examples here before, so i assume that your setup somehow compiles.
Are you doing this since 15 years ?
Edit: there is a "howtobuild.txt" delivered with the code examples describing it. They apparently use gl3w as the loader library.
FFS use an engine or a library.
what is FFS, so I should use an external library? what do you recommend.
2 hours ago, phil67rpg said:what do you recommend.
SFML is great.
I am trying to learn opengl ,what is FFS
https://www.acronymfinder.com/FFS.html (polite form, of course)
As no one really answered the question about "getting OpenGL 4.5 running", you can't because you can't simply link to it in Visual Studio!
To get OpenGL 4.5 profile there is some work to do first that libraries just as GLEW already carry for you. You need to first setup an good old OpenGL context using the usual code shown here (for Windows)
RenderContext Graphics::CreateContext(void* handle, uint8 & colorBits, uint8 & depthBits)
{
HDC dc = GetDC((HWND)handle);
if(dc)
{
PIXELFORMATDESCRIPTOR pfd;
Drough::memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = static_cast<BYTE>(colorBits);
pfd.cDepthBits = static_cast<BYTE>(depthBits);
pfd.iLayerType = PFD_MAIN_PLANE;
int formatId = ChoosePixelFormat(dc, &pfd);
if(formatId && boolean_cast(SetPixelFormat(dc, formatId, &pfd)))
{
colorBits = static_cast<byte>(pfd.cColorBits);
depthBits = static_cast<byte>(pfd.cDepthBits);
HGLRC rc = wglCreateContext(dc);
if(rc)
{
wglMakeCurrent(dc, rc);
return RenderContext((void*)rc, (void*)dc, false);
}
}
DeleteDC(dc);
}
return RenderContext(null_ptr, null_ptr, false);
} You now have a valid GL context of the most common version your driver supports. In my case it is anything arround 3.3. You now have to upgrade your context to certain profile. The reason for that is that choosing certain driver version itself is a function of the driver so you need a generic driver instance first (the common context) and then query for the versions available by your installed graphics driver.
To upgrade the context you need to create a new one and delete the old one with this function (for Windows)
bool Graphics::LoadContext(RenderContext& context, RenderProfile& profile)
{
int32 flags = ((HasFlag(profile.Mask, RenderProfile::ForwardCompatible)) ? WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB : 0);
if(HasFlag(profile.Mask, RenderProfile::Debug))
flags |= WGL_CONTEXT_DEBUG_BIT_ARB;
int32 attributes[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, profile.Version.Major,
WGL_CONTEXT_MINOR_VERSION_ARB, profile.Version.Minor,
WGL_CONTEXT_FLAGS_ARB, flags,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0
};
HGLRC rc = wglCreateContextAttribsARB((HDC)context.deviceHandle, 0, attributes);
if(rc)
{
int32 glVersion[2] =
{
static_cast<int32>(profile.Version.Major),
static_cast<int32>(profile.Version.Minor)
};
glGetIntegerv(Mask(GetPName::TYPE, 0x821B), &glVersion[0]); //Major
glGetIntegerv(Mask(GetPName::TYPE, 0x821C), &glVersion[1]); //Minor
profile.Version.Major = static_cast<byte>(glVersion[0]);
profile.Version.Minor = static_cast<byte>(glVersion[1]);
wglMakeCurrent(0, 0);
wglDeleteContext((HGLRC)context.handle);
wglMakeCurrent((HDC)context.deviceHandle, rc);
context.handle = (void*)rc;
return true;
}
else return false;
} What I'm doing here is defining the GL Version in the attribs array to the desired version and call the ARB extension function. This tries to create a matching context or returns the next available context from the driver. To get shure I got what I requested for, I grab the real version using the glGetInteger functions with the Major- and Minor Version flags specified by the GL standard.
Finally as we now have two contexts and the old one is still in use (even if we didn't render anything so far), I reset the active context to null, delete the old common context we don't need anymore and instead activate my new one so you can start rendering in the desired GL after the function returns true.
Please note that RenderProfile and some other functions I used here are already wrapped into my API for reuse.
Good luck tinkering arround with OpenGL profiles
Hu, got a downvote for saying "get an introductory book and read the instructions". Strange times ...
Anyway, OP has the blue book. It comes with code examples. The setup and initialization of the environment is explained there and it is possible in a few lines of code even on Windows (with glfw for example), though i have not done that myself under windows. But a short search on the internet reveal that this should work.
The above code block is surely brave, but in OP's context unnecessary. The example code should compile with any up to date driver and if not someone still can help.
@phil67rpg, if you don't get the superbible examples to compile, despite of the use of a window handler like glfw3 and an OpenGL loader library like glad2, gl3w or glew and all the tutorials on the internet and the explanations in the accompanying readmes don't help either, then i humbly suggest to not spend any more time on trying and switch to another mode of doing.
Download the Godot Engine (Standard Version with GDScript), play through the tutorials, you can even find a pong demo project in the examples and demo projects. But first, the tutorials. Step by step, every day one step.
I am sure you'll get a feeling of accomplishment much easier (though it might still take a few months) than with all this tedious c++ stuff. Though at any point later you can come back to the lower level C++ and OpenGL, Godot is fully open sauce and c++ ...
Dear downvoter: on the danger of derailing, but for the sake of finding out what's possibly wrong, say, what exactly is the problem with my posts ?
- OpenGL 4.5 can be used in windows with the help of a window handler and a loader library without the need of performing OS specific gymnastics. Is that incorrect ? According to the Red Book (using OpenGL 4.5 in many cases) their examples were compiled with this technique. Source code online on github. Use of a window handler also makes input handling much easier and abstracts the platform specifics away. I must admit, since i am on Linux, i can not check that, but there are extensive "how to"s delivered with both the Red and the Blue book and i would assume that if these did not work, we'd know it. (Like was the case with missing code examples of the Vulkan Programming Guide).
- It seems to me that C++/Api programming is probably not the right approach to game programming for the original poster. A game engine could imo lead to success faster, or else we will continue to run in circles. My suggestion to @phil67rpg is to break the circles with the use of a game engine. Where is the problem with that ?
2 hours ago, Green_Baron said:It seems to me that C++/Api programming is probably not the right approach to game programming for the original poster. A game engine could imo lead to success faster, or else we will continue to run in circles
I feel as I need to write again and take an additionl statement to my previous answer. In general you are right but what I absolutely don't like are answers that lead to the need of using some heavy third-party library without the explaination of why you should better use it ?
The OP explicite asked in his second post how he can link GL 4.5 to Visual Studio and I answered exactly that and also referred to libraries as GLFW already do that for you. Just for notice.
So people be nice to each other and accepting different opinions lead to a better social feeling!
EDIT: I didn't downvote anyone but feel free if you think you need to rage downvote my opinion. It dosent matter nor will it change my statement
39 minutes ago, Shaarigan said:I feel as I need to write again and take an additionl statement to my previous answer. In general you are right but what I absolutely don't like are answers that lead to the need of using some heavy third-party library without the explaination of why you should better use it ?
This is not correct as stated. The why is explained in length & width in the introductory chapters of the books, especially the one the OP mentioned. I would not expect a reasonable person to not use these libraries and save a few hundred lines of platform specific code for window- and input handling, and that for Windows (different Versions), Linux (different window systems and surfaces), Android, Apple, whatever. GLFW (for example) slides in an abstraction layer to free a programmer from this tedious, time consuming, unproductive tasks and it used in the examples. Programming also means building on the work of others to come to a result quickly. That is my downvote to you.
QuoteThe OP explicite asked in his second post how he can link GL 4.5 to Visual Studio and I answered exactly that and also referred to libraries as GLFW already do that for you. Just for notice.
The answer is in the introductory chapter and in the code examples of the book he owns, he only has to read and apply it. Your windowing code in great honour, but it isn't helpful because i doubt it will be understood (i may be wrong here) and it does not solve the problem of further window handling (resize and so on) and input handling (mouse, keyboard), all of which can be solved with a simple include and a few lines of code. A help for the OP will put him on a path of success without too many distractions over tedious sidework that can be avoided.
QuoteSo people be nice to each other and accepting different opinions lead to a better social feeling!
I give that back. I have no problem with your way of addressing window code, it is slightly advanced, but unnecessary in this case. There are quicker and less demanding ways of solving the original question, which should be preferred.
Edit: clarification, because you accused me to introduce heavy weight third party libs and that is the reason for your downvotes: GLFW is not heavy weight and i didn't introduce anything. I simply said: read the instructions. GLFW is used as window/input handler in the example code of the SuperBilde as well as the Programming Guide, and btw. in learnopengl.com and others.
Oh. I thought you were the downvoter. A pity that it is not shown who votes what. Would make it easier to estimate people's alignments ?
I took back my downvote, @Shaarigan.
Seems like our dispute is a perfect example for downvoting in general not being favourable for the quality of posts ?
Just as a small note:
1) moderators can see who downvotes, and can see any abuse of the system being performed. Incorporate that into your mental calculus in these matters.
2) there really is no need for upvotes or downvotes in a phil thread. Please, people, let's keep it civil in the hope that somebody might be able to finally get the light to turn on.
GDNet+ can see clearly also.
@phil67rpg Perhaps your graphics driver does not have support for an ogl4.5 context. (hardware determines max version)
36 minutes ago, GoliathForge said:GDNet+ can see clearly also.
It's the only reason some people even get an account. ![]()
LOL, Downvoted. Preacher telling the truth and it hurts.
He got downvoted 9 times alone in this thread, some of them just for posting. He is probably loosing interest - i am losing interest in helping when being cowardly downvoted for mentioning the documentation.
If phil insists on using C++/OpenGL 4.5 the first step is to set up the environment. Download glfw binaries, and either gl3w or glew. When going thru this i freely admit that it is more complicated for Windows than for Linux because of the Linux packaging systems and repositories.
It would be nice @phil67rpg, if you could confirm that this has been done.
Where-ever in VisualStudio you put your linker directives, include GL and GLEW and glfw (using g++ this is -lGLEW -lGL -lglfw) or gl3w instead of glew.
Then try this little program (i am on linux, could a friendly colleague with a windows environment and glew and glfw pls. confirm that this runs or eventually correct this ?) that just opens a window a closes it again, printing the reported version number in between:
#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main() {
if( GL_TRUE != glfwInit() )
std::cerr << "Error initialising glfw" << std::endl;
// Window and context; we want OpenGL 4.5
glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 );
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 5 );
glfwWindowHint( GLFW_CLIENT_API, GLFW_OPENGL_API );
glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
GLFWwindow *w{ glfwCreateWindow( 800, 600, "Hello world", nullptr, nullptr ) };
if( NULL == w )
std::cerr << "Could not create glfw window\n" << std::endl;
glfwMakeContextCurrent( w );
glewExperimental = true;
GLenum res{ glewInit() };
if( GLEW_OK != res ) {
std::cerr << glewGetErrorString( res ) << std::endl;
std::cerr << "Error initialising glew" << std::endl;
}
GLint vmajor, vminor;
glGetIntegerv( GL_MAJOR_VERSION, &vmajor );
glGetIntegerv( GL_MINOR_VERSION, &vminor );
std::cout << "OpenGL version " << vmajor << '.' << vminor << '\n';
// Here comes your code later !
glfwDestroyWindow( w );
glfwTerminate();
} // ctor If this works, you're ready to use OGL 4.5.
If you have problems at this stage understanding what's going on, then name them. Ignore cowardly downvotes ?
We must find the tubercle ?
This topic has been locked by a moderator. New replies are not allowed.
GameDev.net uses cookies to ensure you have the best experience on our platform. Learn more