PDA

View Full Version : GLSL Issue, How to add this file to vc2010?



reader1
03-09-2015, 01:18 AM
the file name, basic.vert,
//
#version 400
in vec3 VertexPosition;
in vec3 VertexColor;

out vec3 Color;

void main()
{
Color =VertexColor;
gl_Position = vec4(VertexPosition,1.0);
}
How to add it in vc?

reader1
03-09-2015, 01:24 AM
and this , name basic.frag /// they are for gl4.0 sample.
#version 400
in vec3 Color;
out vec4 FragColor;

void main()
{
FragColor = vec4(Color,1.0);
}
////////////////////////////////
The main app is
#pragma comment(lib,"glew32.lib")

#include <GL/glew.h>
#include "textfile.h"

#include <GL/glut.h>
#include <iostream>
using namespace std;

GLuint vShader,fShader;

float positionData[] = {
-0.8f, -0.8f, 0.0f,
0.8f, -0.8f, 0.0f,
0.0f, 0.8f, 0.0f };

float colorData[] = {
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f };

GLuint vaoHandle;//vertex array object
.......

tkausl
03-09-2015, 07:04 AM
How? You don't. This are plain data-files, your exe has to read. Nothing, VS has to compile. After compiling your exe, put them into the Debug-Folder in your Solution-Folder, thats (as default) your "current workingdir" when you start your exe.

reader1
03-09-2015, 07:25 AM
How? You don't. This are plain data-files, your exe has to read. Nothing, VS has to compile. After compiling your exe, put them into the Debug-Folder in your Solution-Folder, thats (as default) your "current workingdir" when you start your exe.

You mean compile them, basic.vert and basic.frag individually into each *.exe, then put the *.exe into debug dir with main prog, then run the main program?

Alfonse Reinheart
03-09-2015, 07:27 AM
No, he means to stick the text files there.

You compile shaders during your program's execution, not at C/C++ compile time.

reader1
03-09-2015, 07:52 AM
I mean how to use them in vc2010, if not use their special complier like NVIDIA FxComposer etc.

Alfonse Reinheart
03-09-2015, 07:58 AM
You use them in VC2010 no differently than in any other toolchain.

The compiler you use is the one that happens at runtime, not at your program's compile time. You load a text file that contains your shader's text, you stick that text string into OpenGL (https://www.opengl.org/wiki/Shader_Compilation), and out comes a compiled, linked program object.

This happens no matter what compiler you use for C++.

reader1
03-09-2015, 07:58 AM
pls show an example, or step by step by use vc. is it:
stck the two files to the debug fold with mainglslpro.exe?

Alfonse Reinheart
03-09-2015, 08:02 AM
pls show an example, or step by step by use vc.

Um, here's an idea. Why don't you follow that nice link I gave you?

And more importantly, if you can't even load a file in a C++ program without someone giving you code to copy-and-paste from, you aren't ready to be doing graphics at all. Learn how to use C++ for a while, then you can learn how to do graphics programming in it.

reader1
03-09-2015, 08:07 AM
You use them in VC2010 no differently than in any other toolchain.

The compiler you use is the one that happens at runtime, not at your program's compile time. You load a text file that contains your shader's text, you stick that text string into OpenGL (https://www.opengl.org/wiki/Shader_Compilation), and out comes a compiled, linked program object.

This happens no matter what compiler you use for C++.
the doc is too loong to read, is there any simpe step to describe how to use it under vc?

Alfonse Reinheart
03-09-2015, 08:24 AM
the doc is too loong, to read is there any simpe step to describe how to use it under vc?

Writing your code for you will do neither of us any good. Also, if you'd actually bothered to even skim that page, you'd find perfectly complete example code showing how to compile shaders.

Also, why do you keep asking about "under vc"? As has been explained to you, which compiler you use is irrelevant!

reader1
03-09-2015, 10:03 AM
Um, here's an idea. Why don't you follow that nice link I gave you?

And more importantly, if you can't even load a file in a C++ program without someone giving you code to copy-and-paste from, you aren't ready to be doing graphics at all. Learn how to use C++ for a while, then you can learn how to do graphics programming in it.
There iis load file func,
initShader("basic.vert","basic.frag");

initVBO();
wherever I put the files, even give the whole path, still fail execution

reader1
03-09-2015, 10:28 AM
const GLchar *vShaderCode = textFileRead(VShaderFile);
and
const GLubyte *vendor = glGetString( GL_VENDOR );//////---<here is error pointer.
const GLubyte *version = glGetString( GL_VERSION );
const GLubyte *glslVersion =
glGetString( GL_SHADING_LANGUAGE_VERSION );
GLint major, minor;
glGetIntegerv(GL_MAJOR_VERSION, &major);
glGetIntegerv(GL_MINOR_VERSION, &minor);
cout << "GL Vendor :" << vendor << endl;
cout << "GL Renderer : " << renderer << endl;
cout << "GL Version (string) : " << version << endl;
cout << "GL Version (integer) : " << major << "." << minor << endl; //here get a strange number
cout << "GLSL Version : " << glslVersion << endl;

when run to this statement, get a error pointer vShaderCode.
cxx0030 can't count expresssion.
what's matter?

reader1
03-09-2015, 10:53 AM
they show
vendor nvidia corp
renderer geforce 9600gt
version <string> 2.1.2
version <integer> -858993460.-858993460 //////not a simple number
glsl version 1.20 nividia via cg compiler

is there any matter with version of nividia card?

Alfonse Reinheart
03-09-2015, 10:56 AM
You are now asking about basic C++ (aka: how to read a text file). That's not an appropriate question for an OpenGL forum.


version <string> 2.1.2
version <integer> -858993460.-858993460 //////not a simple number

That's uninitialized memory. Likely due to the fact that the OpenGL version is 2.1, and therefore the integer-fetching functions didn't exist yet.

What tool are you using that prints this?

reader1
03-09-2015, 10:59 AM
Writing your code for you will do neither of us any good. Also, if you'd actually bothered to even skim that page, you'd find perfectly complete example code showing how to compile shaders.

Also, why do you keep asking about "under vc"? As has been explained to you, which compiler you use is irrelevant!
for I m using vc at present to compile this file. I dont know other compiler, either. I think a skillful programmer out there will find the error as soon as possible, more power than I read the doc to find the error.

reader1
03-09-2015, 11:02 AM
You are now asking about basic C++ (aka: how to read a text file). That's not an appropriate question for an OpenGL forum.



That's uninitialized memory. Likely due to the fact that the OpenGL version is 2.1, and therefore the integer-fetching functions didn't exist yet.

What tool are you using that prints this?

no other than ctl-v, ctl-c.

reader1
03-09-2015, 11:13 AM
and yet the vendor has nothing to do with this statement:
const GLchar *vShaderCode = textFileRead(VShaderFile);
and it has also got error pointer.

reader1
03-10-2015, 06:31 AM
the matter is solved.