Redbook 8th sample code?

Hello,

I recently bought the new redbook 8th and it is really good so far. I also know its not done yet but their website is now down since 2 weeks and I am not able to get the sample code.

http://www.opengl-redbook.com/

Its a little bit annoying because they use their own libraries in the samples. like loadshaders();
I mean it’s not a huge problem but it would definitely help to have to sample code.

Do you have any idea if there is another place where I can get those sample files?

What actual problem do you have? I think we can help.

I think the helper library that they use are only for loading shaders. They probably just didn’t want to overcomplicate the hello world programm. Shaders will be introduced in unit 2.

I think I will be fine.

thanks

Where did you buy the book, and what’s the price?
The book has not been officialy released yet. That’s why I’m asking those questions. :confused:

[QUOTE=Aleksandar;1245806]Where did you buy the book, and what’s the price?
The book has not been officialy released yet. That’s why I’m asking those questions. :confused:[/QUOTE]
you can get it here
http://my.safaribooksonline.com/book/programming/opengl/9780132748445

I just can’t tell you if it is good or bad because I only read the first 2 chapters.
But my first impression is that the book has a good structure.

Also it got it for ~$45 and it is the rough cuts edition obviously. But you always have access to the newest edition online. Also the downloadable pdf version is really really bad formatted, you better read it online.

kantaki, I also registered with Safari Online. It’s a decent book so far. The best resource I’ve found yet. Everything on the web is either outdated, or not well explained.

Check back in a few days or private message me your e-mail. Based on the section “Compiling Shaders” under Chapter 2, I think I can create a LoadShaders.h that simulates the author’s version. All those functions you see in the Compiling Shaders section is basically, I believe, the LoadShaders.h file. When I get it working I’ll e-mail you a copy of my version of the LoadShaders.h and LoadShaders.cpp file. I’ll also post a comment at SafariOnline for that book.

uppppppppppppppppppppppppppppppppppppppppp

@chuatroi123? Huh?

Anyways, I was able to make my own LoadShaders.h and it works! Just like in the book, I was able to get the triangles colored blue.
You can download the code here: LoadShader

#pragma once
// ---------------------------------------------------------------------------
// LoadShader.h
// Quick and dirty LoadShader function for the OpenGL Programming Guide 4.3
// Red Book.
//
// Author: Qoheleth
// http://www.opengl.org/discussion_boards/showthread.php/180175-Redbook-8th-sample-code?p=1245842#post1245842
// ---------------------------------------------------------------------------
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#include "glew.h"
#include "freeglut.h"

struct ShaderInfo {
	GLenum vTarget;
	const char *vShaderFile;
	GLenum fTarget;
	const char *fShaderFile;
};

GLuint LoadShaders( ShaderInfo shaderInfo );
const char* getShaderProgram( const char *filePath, string &shaderProgramText );
// ---------------------------------------------------------------------------
// LoadShader.cpp
// Quick and dirty LoadShader function for the OpenGL Programming Guide 4.3
// Red Book.
//
// Author: Qoheleth
// http://www.opengl.org/discussion_boards/showthread.php/180175-Redbook-8th-sample-code?p=1245842#post1245842
// ---------------------------------------------------------------------------
#include "LoadShader.h"
	
GLuint LoadShaders( ShaderInfo shaderInfo )
{
	GLuint program;
	GLuint vertexShader;
	GLuint fragmentShader;
	vertexShader   = glCreateShader( GL_VERTEX_SHADER );	// create a vertex shader object
	fragmentShader = glCreateShader( GL_FRAGMENT_SHADER );	// create a fragment shader object
	
	// load and compile vertex shader
	string shaderProgramText;
	const char* text = getShaderProgram( shaderInfo.vShaderFile, shaderProgramText );
	GLint length = shaderProgramText.size();
	glShaderSource( vertexShader, 1, &text, NULL );
	glCompileShader( vertexShader );

	for ( int i = 0; i < length; i++ )
	{
		cout << text[ i ];
	}

	GLint status;
	glGetShaderiv( vertexShader, GL_COMPILE_STATUS, &status );

	if ( !( status == GL_TRUE ) )
		cerr << "
Vertex Shader compilation failed..." << '
';

	char *infoLog = new char[ 100 ];
	GLsizei bufSize = 100;
	glGetShaderInfoLog( vertexShader, bufSize, NULL, infoLog );
	for ( int i = 0; i < bufSize; i++ )
		cout << infoLog[ i ];
	delete [] infoLog;

	// load and compile fragment shader
	shaderProgramText = "";
	text = getShaderProgram( shaderInfo.fShaderFile, shaderProgramText );
	glShaderSource( fragmentShader, 1, &text, NULL );
	glCompileShader( fragmentShader );

	glGetShaderiv( fragmentShader, GL_COMPILE_STATUS, &status );

	if ( !( status == GL_TRUE ) )
		cerr << "
Fragment Shader compilation failed..." << '
';

	infoLog = new char[];
	bufSize = 0;
	glGetShaderInfoLog( fragmentShader, bufSize, NULL, infoLog );
	for ( int i = 0; i < bufSize; i++ )
		cout << infoLog[ i ] << endl;
	delete [] infoLog;

	// create the shader program
	program = glCreateProgram();

	// attach the vertex and fragment shaders to the program
	glAttachShader( program, vertexShader );
	glAttachShader( program, fragmentShader );

	// link the objects for an executable program
	glLinkProgram( program );

	glGetProgramiv( program, GL_LINK_STATUS, &status );
	if ( !( status == GL_TRUE ) )
		cout << "Link failed..." << endl;

	// return the program
	return program;
}

const char* getShaderProgram( const char *filePath, string &shader )
{
	fstream shaderFile( filePath, ios::in );

	if ( shaderFile.is_open() )
	{
		std::stringstream buffer;
		buffer << shaderFile.rdbuf();
		shader = buffer.str();
		buffer.clear();
	}
	shaderFile.close();

	return shader.c_str();
}

There is also the Tutorial pages in the Wiki and they have code for reading your shader file.
http://www.opengl.org/wiki/Tutorials

i nÃy hay.dúng lÃ* mình dang c?n thank bác nha