Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

EddieV223

Member Since 24 Oct 2010
Offline Last Active Apr 28 2013 12:13 PM
-----

Topics I've Started

Frustum culling using bounding boxes for objects to cull, need tutorial/example.

10 April 2013 - 12:11 PM

Hi does anyone know of a easy to use tutorial for frustum culling and uses bounding boxes ( not axis aligned ) for the tests?.


Which is easier to program C# or Java?

28 March 2013 - 11:52 PM

Hello, I am not trying to start a language war here.  I am a c++ programmer, I wouldn't say I'm a pro, but I'm pretty good.  It has been increasing clear to me that c++ is not as productive as languages such as c# and java.  

 

I am looking to learn a second language and use it for things like making GUI applications quicker and easier than c++.  The type of application that absolute speed of the application is not paramount, but making it quickly and easily is more important.

 

So it seems like for general purpose languages that strive for productivity, C# and Java are the top 2.  Which is the easiest to use for making general purpose programs with GUI's?


OpenAL why is there no group working on it?

18 March 2013 - 02:30 PM

Why is openAL not being developed?  We need a hardware accelerated cross platform API for audio, like openGL is for graphics!  

 

I will never forgive Microsoft for removing the audio HAL from windows.


Log text file. Need a tool that can keep my log file open and auto reload it when it c...

02 March 2013 - 02:39 PM

Hi I have a game I am working on, it has a logger class.  This class stores a string stream, and then dumps it to a text file when the application closes.

 

What I want to be able to do is have it open in some kind of text editor and have it reload automatically whenever the program changes the log file.  

 

However if I try to use visual studio it always prompts that the file has changed would you like to reload it, this gets very annoying after hours of programming.  I tried notepad, but it doesn't even know when the file changes and so you have to close it and reopen it again every time.  I tried word pad, it grabs control of the file and doesn't let my application modify it.  Libre office does the same thing.  

 

So what text editor can I use that will not block the file from changing but also automatically update when the file contents change?


Please help 2 days stuck, simple openGL app doesn't render anything!

20 February 2013 - 02:54 PM

Here is a link to my vs11 express project.

http://www.filehosting.org/file/details/421749/OpenGLSpaceShip.7z

 

All it does is render the clear color it doesn't render my objects, I have tried loading from my obj loader and also just using vertex and index buffer from a working tutorial, neither work.

 

It is really just 1 Graphics class so it's not complicated code.  For 2 days I struggle with this, since I am new to openGL I don't know what is wrong and have been trying to fix it for days now.  

 

Here is the graphics class.

 

// header

#pragma once

#include "GL\glew.h"
#include "GL\freeglut.h"

#define GLM_FORCE_RADIANS
#include <glm.hpp>
#include <gtc/matrix_transform.hpp>

class Graphics
{
public:
	Graphics();
	~Graphics();

	bool Init(int argc, char* argv[]);

	bool InitWindow(int argc, char* argv[]);

	void StartGlutLoop();

	bool LoadGraphics();
	void UpdateGraphics();
	void RenderGraphics();
	void CleanGraphics();

	int mWindowHandle;

	GLuint mVAO;
	GLuint mVBOCube;
	GLuint mVBOCubeIndices;
	GLuint mCubeIndexCount;

	GLuint mBasicShaderProgram;

	glm::mat4 mView;
	glm::mat4 mProj;
	glm::mat4 mProjView;
	glm::mat4 mCubeWorld;
};

// CPP


#include "Graphics.h"

#include "main.h"

Graphics::Graphics()
	{
	}


Graphics::~Graphics()
	{
	}

bool Graphics::Init(int argc, char* argv[])
	{
	GLenum glewInitResult;
	InitWindow(argc, argv);
	GLenum error = glGetError();
	
	glewExperimental = GL_TRUE;
	glewInitResult = glewInit();
	error = glGetError();
	if ( glewInitResult != GLEW_OK )	
		{
		cout << glewGetErrorString(error) << '\n';
		exit(EXIT_FAILURE);
		return false;
		}
	
	error = glGetError();
	// this triggers 1280 GL_INVALID_ENUM this is before I even set any gl enums manually
	if ( error != GL_NO_ERROR )	
		{
		cout << glewGetErrorString( error );
		exit(-1);
		return false;
		}
	glEnable(GL_DEPTH_TEST);
	glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
	if (LoadGraphics())
		return true;
	else
		{
		return false;
		}
	}

bool Graphics::InitWindow(int argc, char* argv[])
	{
	glutInit(&argc, argv);

	glutInitContextVersion(4, 0);
	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
	glutInitContextProfile( GLUT_CORE_PROFILE );

	glutSetOption( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS );

	glutInitWindowSize( 800, 600 );
	
	glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );

	mWindowHandle = glutCreateWindow("Hello World!");

	if ( mWindowHandle < 1 )
		{
		exit(EXIT_FAILURE);
		}
	// TODO: add callbacks for freeGLUT
	glutIdleFunc( Update );
	glutDisplayFunc( Render );
	glutCloseFunc( Close );
	
	return true;
	}

bool Graphics::LoadGraphics()
	{
	GLenum error = glGetError();
	if ( error != GL_NO_ERROR )
		{
		cout << glewGetErrorString(error) << '\n';
		exit(-1);
		return false;
		}
	typedef struct
{
    float XYZW[4];
} Vertex2;

	Vertex2 vertices[] =
{
    { { 0.0f, 0.0f, 0.0f, 1.0f } },
    // Top
    { { -0.2f, 0.8f, 0.0f, 1.0f } },
    { { 0.2f, 0.8f, 0.0f, 1.0f } },
    { { 0.0f, 0.8f, 0.0f, 1.0f }},
    { { 0.0f, 1.0f, 0.0f, 1.0f }},
    // Bottom
    { { -0.2f, -0.8f, 0.0f, 1.0f } },
    { { 0.2f, -0.8f, 0.0f, 1.0f } },
    { { 0.0f, -0.8f, 0.0f, 1.0f } },
    { { 0.0f, -1.0f, 0.0f, 1.0f } },
    // Left
    { { -0.8f, -0.2f, 0.0f, 1.0f } },
    { { -0.8f, 0.2f, 0.0f, 1.0f } },
    { { -0.8f, 0.0f, 0.0f, 1.0f } },
    { { -1.0f, 0.0f, 0.0f, 1.0f } },
    // Right
    { { 0.8f, -0.2f, 0.0f, 1.0f } },
    { { 0.8f, 0.2f, 0.0f, 1.0f } },
    { { 0.8f, 0.0f, 0.0f, 1.0f }},
    { { 1.0f, 0.0f, 0.0f, 1.0f } }
};

GLubyte indices[] = {
    // Top
    0, 1, 3,
    0, 3, 2,
    3, 1, 4,
    3, 4, 2,
    // Bottom
    0, 5, 7,
    0, 7, 6,
    7, 5, 8,
    7, 8, 6,
    // Left
    0, 9, 11,
    0, 11, 10,
    11, 9, 12,
    11, 12, 10,
    // Right
    0, 13, 15,
    0, 15, 14,
    15, 13, 16,
    15, 16, 14
};


	// create VBO
	OBJLoader loader;
	
	UPMesh upMesh = loader.Load( "c:\\objBox.obj" );

	glGenBuffers(1, &mVBOCube);
	glBindBuffer(GL_ARRAY_BUFFER, mVBOCube);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW );
	//glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex2) * upMesh->mVertices.size(), upMesh->mVertices.data(), GL_STATIC_DRAW );

	glGenBuffers(1, &mVBOCubeIndices);
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mVBOCubeIndices);
	glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW );
	//glBufferData( GL_ELEMENT_ARRAY_BUFFER, sizeof(upMesh->mIndices[0]) * upMesh->mIndices.size(), upMesh->mIndices.data(), GL_STATIC_DRAW );

	
	// create VAO
	glGenVertexArrays(1, &mVAO);
	glBindVertexArray(mVAO);
	error = glGetError();

	if ( error != GL_NO_ERROR )
		{
		cout << glewGetErrorString( error ) << '\n';
		exit(-1);
		return false;
		}
	
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0 );
	//glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(3 * sizeof(GLfloat)) );
	//glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, (void*)(5 * sizeof(GLfloat)) );
	error = glGetError();

	if ( error != GL_NO_ERROR )
		{
		cout << glewGetErrorString( error ) << '\n';
		exit(-1);
		return false;
		}
	
	glEnableVertexAttribArray(0);
	//glEnableVertexAttribArray(1);
	//glEnableVertexAttribArray(2);
	

	mCubeIndexCount = upMesh->mIndices.size();

	mView = glm::lookAt( glm::vec3(0.f,0.f,10.f), glm::vec3(0.f,0.f,0.f), glm::vec3(0.f, 1.0f, 0.f));
	mProj = glm::perspective( 3.14f / 2.0f, 800.f / 600.f, 0.1f, 1000.f );
	mProjView = mProj * mView;

	mCubeWorld = glm::mat4(1.0f);

	error = glGetError();

	if ( error != GL_NO_ERROR )
		{
		cout << glewGetErrorString( error ) << '\n';
		exit(-1);
		return false;
		}

	ifstream ifs;
	ifs.open( "..\\Resources\\basicShader.vertex", ios::in );
	if ( !ifs.good() )
		{
		cout << "ifs open failed.\n";
		exit(-1);
		return false;
		}
	string buffer;
	string errorBuffer;
	errorBuffer.reserve(2048);
	string shaderCode;
	while ( getline(ifs, buffer ) )
		{
		shaderCode += buffer += '\n';
		}
	char const * pSource = shaderCode.c_str();	
	GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
	glShaderSource( vertShader, 1, &pSource, NULL );
	glCompileShader(vertShader);
	glGetShaderInfoLog( vertShader, 2047, NULL, &errorBuffer[0] );
	ifs.close();
	
	error = glGetError();
	ifs.open( "..\\Resources\\basicShader.fragment", ios::in );
	if ( !ifs.good() )
		{
		exit(-1);
		return false;
		}

	shaderCode.clear();
	while ( getline( ifs, buffer ) )
		{
		shaderCode += buffer += '\n';
		}
	pSource = shaderCode.c_str();
	GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource( fragShader, 1, &pSource, NULL );
	glCompileShader( fragShader );
	glGetShaderInfoLog( fragShader, 2047, NULL, &errorBuffer[0] );
	mBasicShaderProgram = glCreateProgram();
	glAttachShader(mBasicShaderProgram, vertShader);
	glAttachShader(mBasicShaderProgram, fragShader);
	glLinkProgram( mBasicShaderProgram );
	glGetProgramInfoLog( mBasicShaderProgram, 2047, NULL, &errorBuffer[0] );
	glUseProgram( mBasicShaderProgram );

	error = glGetError();

	if ( error != GL_NO_ERROR )
		{
		cout << glewGetErrorString(error) << '\n';
		exit(-1);
		return false;
		}

	return true;
	}

void Graphics::UpdateGraphics()
	{
	glutPostRedisplay();
	}

void Graphics::RenderGraphics()
	{
	static float color = 0.0;
	static float dir = 1.0;
	color += (.0001f * dir);
	if ( 1.0f < color )
		{
		color = 0.999f;
		dir *= -1.0f;
		}
	if ( color < 0.0f )
		{
		color = 0.0001f;
		dir *= -1.0f;
		}
	glClearColor( color, color, color, 0.0);
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

	glm::mat4 mvp = mProjView * mCubeWorld;

	GLint location = glGetUniformLocation(mBasicShaderProgram, "world");

	glProgramUniformMatrix4fv( mBasicShaderProgram, location, 1, GL_FALSE, &mvp[0][0] );

	glDrawElements( GL_TRIANGLES, mCubeIndexCount, GL_UNSIGNED_INT, (void*)0);

	glutSwapBuffers();
	glutPostRedisplay();

	GLenum error = glGetError();
	if ( error != GL_NO_ERROR )
		{
		cout << glewGetErrorString(error) << '\n';
		exit(-1);
		return;
		}
	}

void Graphics::CleanGraphics()
	{
	glDisableVertexAttribArray(mVAO);
	glDisableVertexAttribArray(0);

	glBindVertexArray(0);
	glDeleteVertexArrays(1, &mVAO);

	glBindBuffer( GL_ARRAY_BUFFER, 0 );

	glDeleteBuffers(1, &mVBOCube);

	GLenum error = glGetError();
	if ( error != GL_NO_ERROR )
		{
		exit(-1);
		}
	}

void Graphics::StartGlutLoop()
	{
	glutMainLoop();
	}

PARTNERS