Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

OpenGL opengl 4.5

Recommended Posts

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);
}

 

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)

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.

 

Edited by Green_Baron

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Posted (edited)

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.
 

 

Edited by Green_Baron

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!