Jump to content

  • Log In with Google      Sign In   
  • Create Account


GothSeiDank

Member Since 22 Oct 2007
Offline Last Active Nov 13 2013 05:04 AM
***--

#4872899 OpenGL 3.x/4.x static libraries?

Posted by GothSeiDank on 15 October 2011 - 11:09 AM

@V-Man
Glew is a bad idea for OpenGL 3 and 4 since it uses deprecated ways to get the extensions and causes Warnings.

@Asesh
GL3w works on Windows and Linux as far as I can see. Yes, it is the same case.
The python script generates a file dependant on your platform which you can include into your project.


#4872835 OpenGL 3.x/4.x static libraries?

Posted by GothSeiDank on 15 October 2011 - 07:31 AM

Use gl3w.
It does the Job for you.


#4846474 Custom Vertex structure

Posted by GothSeiDank on 08 August 2011 - 07:26 PM

This is my vertex structure, also for 2D:


struct NLVertexData
{
	/// \brief Constructor
	NLVertexData()
		: x(0), y(0), z(0),
		r(1), g(1), b(1), a(1), 
		s(0), t(0)
	{}

	/// \brief X
	f32 x;

	/// \brief Y
	f32 y;	

	/// \brief Z
	f32 z;

	/// \brief Red
	f32 r;

	/// \brief Green
	f32 g;

	/// \brief Blue
	f32 b;

	/// \brief Alpha
	f32 a;

	/// \brief s
	f32 s;

	/// \brief t
	f32 t;
};

That makes a size of 36 bytes per Vertex.
That leads to the following Vertex Attribute Set:

	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(NLVertexData), 0);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(NLVertexData), (void*)(3*sizeof(float)));
	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(NLVertexData), (void*)(7*sizeof(float)));

Shader-Layout:

layout(location = 0) in vec3 Vertex;
layout(location = 1) in vec4 Color;
layout(location = 2) in vec2 TextureCoord;

So yes, you need only 1 set of texture-coordinates per Vertex. Don't know why they use it like this in that tutorial.
Why they are called S and T is something I did not figure out after reading 3 Books and an unknown amount of websites regarding the topic :P.
I just take it as a given naming :lol:.

Good Tutorial:

Learning Modern 3D Graphics Programming Through OpenGL


#4845608 2D Animation in OpenGL

Posted by GothSeiDank on 06 August 2011 - 06:04 PM

SpriteSheets are the way to go. In my 2D Engine, I use this Tool:
Very nice and easy to use, even has a commandline tool coming with it.
Implementation for a parser of the format:
http://code.google.com/p/nightlight2d/source/browse/NightLightDLL/NLSpriteSheet.cpp

And animating is just flipping the texture-coords.
In my code, I just keep all frames in a vector, which are described in a xml document and all frames live on the same spritesheet.
Then every X seconds or frames I flip the texture-coords of the sprite and voilá, decent animation :).

http://code.google.c...NLAnimation.cpp
Thats the code without drawing the sprite, that is done in another class since this is a derived class only. But could give a clue about how to do it.
The code should be easy to understand.
Believe me, Spritesheets really speed you up and flipping the texture-coords is the most efficient way you can have when doing pic-by-pic animations.
Thats at least what I researched.


#4845606 Difference between OpenGL 2.1 and 3.0?

Posted by GothSeiDank on 06 August 2011 - 05:56 PM

I'm starting to like the idea of having different rendering configurations (disabling unsupported features according to system specs). I could make some graphics wrappers and use those to encapsulate various collections of dynamic libraries (holding the platform-specific functionality), depending on the OGL version supported. That way my code will be lighter and I can leave it to an installer to provide the correct libraries depending on the system specs.

This might be a bit more work, but it does give me a better perspective of how I should manage the platform-specific code. I suppose the real question is how to write these theoretical "graphics wrappers"... Also, what are fixed functions? Do they basically manipulate the graphics pipeline?


Fixed Functions is the non-programmable pipeline in OpenGL. As I said it is functions like glMultMatrix, glMatrixMode etc.

On your other problem:
If you want the same code with 2 different backends, use the pimpl-idiom.
Like this, assuming C++:



class OpenGL
{
public:
	virtual void draw_something()
	{}
};

class OpenGL2 : public OpenGL
{
public:
	virtual void draw_something() {}
};

class OpenGL3 : public OpenGL
{
public:
	virtual void draw_something() {}
};


class FrontendAPI
{
public:
   FrontendAPI(int OpenGLVersion) 
   {
   	if ( OpenGLVersion == 2 )
   	{
			m_impl = new OpenGL2();			
   	}
   	else if ( OpenGLVersion == 3 )
   	{
			m_impl = new OpenGL3();
   	}		
   };
   
   void draw_something() 
   {
		m_impl->draw_something();
   }
   
private:
   OpenGL* m_impl;
}




#4845589 Difference between OpenGL 2.1 and 3.0?

Posted by GothSeiDank on 06 August 2011 - 04:39 PM

The main difference in 3.0 is, that all fixed functions are gone. No more glMultMatrix, glLoadMatrix etc.
You have to do that with shaders.
GLM is a library that helps here, since it is written against the glsl spec and can dirctly be transmitted to the shader.
It also provides a replacement of glOrtho and glFrustum etc.
capricorn already pointed out VBOs.
Have a look here:
Learning Modern 3D Graphics Programming Through OpenGL


#4833541 Free GPU Memory after deleting texture

Posted by GothSeiDank on 10 July 2011 - 06:54 PM

Use gDebugger and see if he reports a memory leak. It is a very good and free OpenGL Debugger.

http://www.gremedy.com/


#4823850 A decent OpenGL2D Tutorial

Posted by GothSeiDank on 15 June 2011 - 05:43 PM

Hi Kurt.
I am a hobbiest using OpenGL.

What you have to do:
First, let me tell you that most OpenGL Tutorials on the Web are outdated. Unfortunately. You should not use glVertex3f etc anymore, meaning Immediate Mode. Also, Fixed Function Pipeline, meaning OpenGL2 is outdated and should not be used anymore.
Actually, people should learn and use OpenGL3. Best way to learn OpenGL is to read the "OpenGL Superbible, 5th Edition". It covers most techniques.
To get you going, I can show you the basic things needed:

Window Manager Library, I recommend GLUT for you as Beginner or SDL 1.3 or even SFML.
While SFML cannot create a core context (which denies you using deprecated functions).

GLew or GLee. This is a library for loading extensions from the Drivers and you don't have to go through this pain.

glm. This is a math library for OpenGL, written against the Shaderspec 3.0 of OpenGL.

Now I show you in a rough overview how someone renders:
You push your data into a Vertex Buffer Object. This gets uploaded to the Videocard.
Then you tell OpenGL whats in it by defining Attribute Sets.
You can use those Attribute sets in shaders.
You should have Vertices, and TextureCoords there.
The Vertices are multiplied in the Shader with the ViewMatrix which you have to send to the Shader using OpenGL.
The matrix should be a orthographic one, if you want 2D.
This can be achieved with OpenGL and glm like this:

glm::mat4 viewmatrix = glm::ortho<float>(0.0f, x, y, 0, -1.0f, 1.0f); 
int position = glGetAttribLocation(shaderID, "myProjectionMatrix"); 
glUniformMatrix4fv(position, 1, false, glm::value_ptr(viewmatrix ));
Note, that you need a bound shader while doing this.

Here is a basic Shader:

// Vertex Shader:

#version 330

//----------------------------------------------
// Layout Vars
//----------------------------------------------
layout(location = 0) in vec3 NL_Vertex;
layout(location = 1) in vec4 NL_Color;
layout(location = 2) in vec2 NL_TextureCoord;

//----------------------------------------------
// Uniforms from NightLight
//----------------------------------------------
uniform mat4 NL_ProjectionMatrix;

//----------------------------------------------
// Output to fragment shader
//----------------------------------------------
smooth out vec4 theColor;

void main()
{	
	//----------------------------------------------
	// Applying position
	//----------------------------------------------
	gl_Position = NL_ProjectionMatrix*vec4(NL_Vertex, 1.0);

	//----------------------------------------------
	// Output
	//----------------------------------------------
	theColor = NL_Color;
}

// Fragment Shader:

#version 330

smooth in vec4 theColor;

out vec4 outputColor;

void main()
{   
	outputColor = theColor;
}


All it does is to apply the Viewmatrix to each Vertex and uses the colors defined in the VBO to display the object.

I hope you got a rough overview, but best thing to start learning is here:
Learning Modern 3D Graphics Programming Through OpenGL

You can also have a look into the sourcecode of my project, it uses OpenGL3 Core and is heavily documented, maybe it helps you getting an idea:
http://code.google.com/p/nightlight2d/source/browse/trunk/NightLightDLL/


#4799318 creating exe file for opengl game

Posted by GothSeiDank on 16 April 2011 - 06:08 PM

If he uses .dlls like GLUT, he should not link statically. Not at all.
Instead, deliver the Microsoft Runtime Installer and link dynamically.
You said you have C++ Code in Visual Basic? That is not possible at all.
Assuming you use Visual C++ with SP1 2008 you need to give this installer with your program:
http://www.microsoft.com/Downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2


#4796878 C, C# or C++?

Posted by GothSeiDank on 10 April 2011 - 06:23 PM

To be honest, I would start with C++ then C# and would leave C alone first.
Why?
Many C# or Java Programmers going over to C++ have a bad habit in using new for everything, but never delete. I see this on various forums all day.
C Programmers going over to C++ have the bad habbit in writing C with Classes and ignoring C++ Features like Vectors, Strings etc and pack everything and their mother into Arrays and void-pointers, giving up typesafety of C++.

Thats very zynical, I know. But is the daily truth to some degree. May not fit upon you, but fits on many other people :D.
You can see "C with Classes" a lot when students from University are posting Threads with the tasks from their professors. :lol::cool:


#4796550 free for commercial use programming language?

Posted by GothSeiDank on 09 April 2011 - 07:10 PM


The express version is free.


Thanks just started downloading it sounds like just what we need :rolleyes:


You also want to have a look at https://github.com/ for sharing the source code in your team.
There are also some free svn hubs, which allow closed source development.


#4794406 TempAu C++ Audio Library

Posted by GothSeiDank on 04 April 2011 - 05:07 PM

I recommend to use the Apache License, since it does not force you to give away the Source Code.


#4794401 Developing FPSs

Posted by GothSeiDank on 04 April 2011 - 04:51 PM

You could start by learning the UDK :).
http://www.udk.com/download
It is the Unreal Development Kit, which helps you understand this huge engine.
Always a good start to learn something about how Games are made in the Industry.


#4792308 Two questions.

Posted by GothSeiDank on 30 March 2011 - 01:47 PM

I got a reference book and it is quite useful for me, but it is in German and there is no english translation for this one. But there are surely some others, but I cannot recommen them unless I know them.
As for SDL: I want to recommend SFML over SDL since SFML is OOP and C++, SDL is C.


#4792295 static class vs this?

Posted by GothSeiDank on 30 March 2011 - 01:26 PM

If you want Log to be available with the same instance everywhere, think about using a Singleton.

class Log : public boost::noncopyable
{
private:
 	Log()
	{}

public:
 	static Log& getInstance()
	{
 		static Log OnlyOne;
 		return OnlyOne;
	}

	void createLog() 
	{
 		// .....
	}

   void logIt(int, string&)
   {}
};

#define LOGERROR(s)	Log::getInstance().logIt(L_ERROR, s)

int main()
{
	Log::getInstance().createLog();
	LOGERROR("I am feeling depressed.");
}

Static Values can also be used to define Strings or things used over the whole program:
class Math
{
	static double PI;
};

double Math::PI = 3.14159265;

int main()
{
	using namespace std;
	cout << "PI is exactly: " << Math::PI << endl;
}





PARTNERS