PDA

View Full Version : Wrong light



mairan21
01-16-2015, 04:39 PM
What is wrong with my light?
What should I do to get a light-Phong or some realistic?
My light:

float vec[4];
SET_VEC4(vec, -10.7f, -posY, 0.4f, 1.0f);
glLightfv(GL_LIGHT3, GL_POSITION, vec);

SET_VEC4(vec, 0.9f, 0.9f, 0.9f, 1.0f);
glLightfv(GL_LIGHT3, GL_DIFFUSE, vec);

SET_VEC4(vec, 0.0f, 0.0f, 0.0f, 1.0f);
glLightfv(GL_LIGHT3, GL_AMBIENT, vec);

SET_VEC4(vec, 0.05f, 0.05f, 0.05f, 1.0f);
glLightfv(GL_LIGHT3, GL_EMISSION, vec);

SET_VEC4(vec, 0.003f, 0.003f, 0.003f, 1.0f);
glLightfv(GL_LIGHT3, GL_SPECULAR, vec);


float m1_amb[] = { 0.0005f, 0.0005f, 0.0005f };
float m1_dif[] = { 0.5f, 0.5f, 0.5f };
float m1_spe[] = { 0.5f, 0.5f, 0.5f };
float m1_em[] = { 0.4f, 0.4f, 0.4f };
glMaterialfv(GL_FRONT, GL_AMBIENT, m1_amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, m1_dif);
glMaterialfv(GL_FRONT, GL_SPECULAR, m1_spe);
glMaterialfv(GL_FRONT, GL_EMISSION, m1_em);

http://i.imgur.com/ucrdrNK.png
http://i.imgur.com/yWeJfVZ.png
http://i.imgur.com/1wlogq8.png
http://i.imgur.com/6bo7j4O.png

Alfonse Reinheart
01-16-2015, 07:20 PM
What should I do to get a light-Phong or some realistic?

Stop using deprecated OpenGL lighting stuff and start using shaders. You'll have to unlearn a lot of bad habits, but it's worth it.

mairan21
01-17-2015, 01:08 AM
I am new to Opengl, could you tell me how to do these shaders ?

mairan21
01-17-2015, 07:08 AM
I have error when I use shader_vp = glCreateShader(GL_VERTEX_SHADER);

http://i.imgur.com/cOdo6RR.jpg


using namespace std;

static char* textFileRead(const char *fileName) {
char* text;

if (fileName != NULL) {
FILE *file = fopen(fileName, "rt");

if (file != NULL) {
fseek(file, 0, SEEK_END);
int count = ftell(file);
rewind(file);

if (count > 0) {
text = (char*)malloc(sizeof(char)* (count + 1));
count = fread(text, sizeof(char), count, file);
text[count] = '\0';
}
fclose(file);
}
}
return text;
}

Shader::Shader() {

}

Shader::Shader(const char *vsFile, const char *fsFile) {
init(vsFile, fsFile);
}

void Shader::init(const char *vsFile, const char *fsFile) {
shader_vp = glCreateShader(GL_VERTEX_SHADER);
shader_fp = glCreateShader(GL_FRAGMENT_SHADER);

const char* vsText = textFileRead(vsFile);
const char* fsText = textFileRead(fsFile);

if (vsText == NULL || fsText == NULL) {
cerr << "Either vertex shader or fragment shader file not found." << endl;
return;
}

glShaderSource(shader_vp, 1, &vsText, 0);
glShaderSource(shader_fp, 1, &fsText, 0);

glCompileShader(shader_vp);
glCompileShader(shader_fp);

shader_id = glCreateProgram();
glAttachShader(shader_id, shader_fp);
glAttachShader(shader_id, shader_vp);
glLinkProgram(shader_id);
}

Shader::~Shader() {
glDetachShader(shader_id, shader_fp);
glDetachShader(shader_id, shader_vp);

glDeleteShader(shader_fp);
glDeleteShader(shader_vp);
glDeleteProgram(shader_id);
}

unsigned int Shader::id() {
return shader_id;
}

void Shader::bind() {
glUseProgram(shader_id);
}

void Shader::unbind() {
glUseProgram(0);
}

I try include this 2 codes but i have the same problem.
http://mbsoftworks.sk/index.php?page=tutorials&series=1&tutorial=17
http://www.swiftless.com/tutorials/glsl/1_setup.html#DL

ok problem gone.
GLenum err = glewInit();
but my shaders doesn't work ; /