Archive

Archive for the ‘GLSL’ Category

GLSL: Accessing one row of the texture

//Fragment Shader Program to access texture and just copying one row to other

uniform sampler2D textureX;
uniform float        texRows;
uniform float        texCols;

void main(void) {
//cols                rows
vec4 x            = texture2D(textureX, vec2(gl_TexCoord[0].s, gl_TexCoord[0].t+1.0/texRows));
gl_FragColor    = x;

}

Categories: C++, GLSL, Opengl, Texture Tags: ,

GLSL Texture

Coordinates of the gl_TexCoord[0]

gl_TexCoord[0].t —— rows

gl_TexCoord[0].s ——cols

vec4 x = texture2D(textureX, vec2(Columns, rows));

gl_FragColor = x;

Categories: C++, GLSL, Opengl Tags: ,

Assignment 3; Textures Very Imp Links

April 27, 2008 Leave a comment

Use glEnable(GL_TEXTURE_2D);

GPU Programming Course http://www.evl.uic.edu/aej/594/

For the Multi Texturing refer to 

http://www.clockworkcoders.com/oglsl/tutorial8.htm

glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, texture1);
glEnable(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);

glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, texture2);
glEnable(GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_INCR);
http://www.evl.uic.edu/aej/594/lecture04.html
http://www.research.rutgers.edu/~sueda/428Fall2005/proj3.html

Texture Rectangle
http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt

The Dominick Page
http://www.mathematik.uni-dortmund.de/~goeddeke/gpgpu/tutorial.html
http://www.mathematik.uni-dortmund.de/~goeddeke/gpgpu/saxpy_glsl2.cpp
http://code.google.com/p/matpix/source/browse/trunk/src/helloGPGPU.cpp
Categories: C++, GLSL, Opengl Tags: ,

Settingup Texture to read the Frame Buffer

April 26, 2008 Leave a comment

<good link http://www.mathematik.tu-dortmund.de/~goeddeke/gpgpu/saxpy_glsl.cpp>

These are basic steps to take

For each texture do the following things

1) Generate the texture 

glGenTextures(1, texId);

2) Then Bind the texture to what target you want 

glBindTexture( GL_TEXTURE_RECTANGLE_ARB, tex);

3) Setup the properties to avoid the wraping on edges, min-mapping,

glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//clamp so that it does not excede where you do want to write
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);

4) Use the  glTexImage2D to setup the properties like for format, type, height and width of the texture

 

Categories: C++, GLSL, Opengl Tags: , ,

(ReadShader)Simple File Reading Code in C++ with File Size buffer

April 5, 2008 Leave a comment

//impressed by lighthouse 3d and help taken from sources on the internet.
//this is not my idea, not my full code.

//It reads the full file in single go.
#ifndef READSHADER_H
#define READSHADER_H
#include
#include

using namespace std;

char * readShader(char *fileName){

cout <<“nothing”;
ifstream input(fileName);
if(!input){
cout << endl << “UNABLE TO OPEN FILE ” << fileName <<endl;
return 0;
}

int st = input.tellg();
input.seekg(0, ios::end);
int end = input.tellg();
int fileSize = end – st;
if(fileSize <= 0){return 0;}

char *data = new char[fileSize+50];//50 added to just have buffer
memset(data, ”,fileSize+10);
input.seekg(0, ios::beg);

input.read(data,fileSize);
input.close();
data[fileSize]= ”; //appending the zero as the read does not append that
return data;

};
#endif

OpenGl Shader Programming: Getting Started

March 19, 2008 Leave a comment

Download “The OpenGL Extension Wrangler Library” and put the files as described there.

Run glewinfo.exe to see if your graphics card supports the Opengl GLSL Shader library.

Try some code, I downloaded the program given my TA.

But there was error coming as

main.obj : error LNK2001: unresolved external symbol __imp____glewGetInfoLogARB
main.obj : error LNK2001: unresolved external symbol __imp____glewGetObjectParameterivARB
main.obj : error LNK2019: unresolved external symbol __imp__glewInit referenced in function “bool __cdecl init(void)” (?init@@YA_NXZ)
main.obj : error LNK2001: unresolved external symbol __imp____glewUniform1i
main.obj : error LNK2001: unresolved external symbol __imp____glewUniform4f
main.obj : error LNK2001: unresolved external symbol __imp____glewGetUniformLocation
main.obj : error LNK2001: unresolved external symbol __imp____glewUseProgram
main.obj : error LNK2001: unresolved external symbol __imp____glewLinkProgram
main.obj : error LNK2001: unresolved external symbol __imp____glewAttachShader
main.obj : error LNK2001: unresolved external symbol __imp____glewCreateProgram
main.obj : error LNK2001: unresolved external symbol __imp____glewCompileShader
main.obj : error LNK2001: unresolved external symbol __imp____glewShaderSource
main.obj : error LNK2001: unresolved external symbol __imp____glewCreateShader
Debug/test2.exe : fatal error LNK1120: 13 unresolved externals

To resolve this error I searched on the internet and found this

http://www.gamedev.net/community/forums/topic.asp?topic_id=472791

“Expand Configuration Properties>Linker>Input
add glew32.lib (for example) to the Additional Dependencies box.” by Matthughes

Categories: GLSL, Opengl Tags: , ,