Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7189647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:20:47+00:00 2026-05-28T19:20:47+00:00

I have got problem with my shaders. I am trying to put textures and

  • 0

I have got problem with my shaders. I am trying to put textures and phong shading in my game using glsl but I can’t get any good effect.

I’ve been searching google for a long time, and I can’t find any info how connect ligh and texture together, so I’ve decided to wrote and ask here.

This is my game without texture:
without texture

and this is with texture:

with texture

What I want to achive is to make this pinkish texture make better visible with spot on a center – just like without texture, and also repair those per vertex shading on gutters – make it per pixel shading, I don’t know what is wrong now.

I have checked about 10 shaders with phong shading and I have got also per vertex not per pixel shading.

This is my fragment vertex code mayby someone can see there something?

    varying vec3 N;
    varying vec3 v; 
    uniform sampler2D myTexture;

    varying vec2 vTexCoord;    

    void main (void)  
    {  
       vec4 finalColor = vec4(0.0, 0.0, 0.0, 0.0);

vec3 L = normalize(gl_LightSource[0].position.xyz - v);   
           vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)  
           vec3 R = normalize(-reflect(L,N));  

           //calculate Ambient Term:  
           vec4 Iamb = gl_FrontLightProduct[0].ambient;    

           //calculate Diffuse Term:  
           vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);    

           // calculate Specular Term:
           vec4 Ispec = gl_FrontLightProduct[0].specular 
                        * pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);

            finalColor+=Iamb + Idiff + Ispec;
       // write Total Color:
       gl_FragColor = gl_FrontLightModelProduct.sceneColor + (texture2D(myTexture, vTexCoord)) + finalColor;
    }

and my vertex shader

varying vec3 N;
varying vec3 v;
varying vec2 vTexCoord;

void main(void)
{

   v = vec3(gl_ModelViewMatrix * gl_Vertex);       
   N = normalize(gl_NormalMatrix * gl_Normal);
   vTexCoord = vec2(gl_MultiTexCoord0);

   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;


}

I’ll be glad for help.

EDIT:

this is how I put my texture into shader. It works fine ( I think ) because I can edit texture values in shader – in some way.

int my_sampler_uniform_location = glGetUniformLocation(brickProg, "myTexture");

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);

glUniform1i(my_sampler_uniform_location,0);
CUTIL::drawBox();
glBindTexture(GL_TEXTURE_2D,0);

EDIT 2:

After Nicol Bolas suggestion about colors add I have edited my shader and change it like this:

gl_FragColor = (texture2D(myTexture, vTexCoord)) + finalColor;

Now it is only to bright, but now I have to chenge a little light on stage and would be great. But still I haven’t got per pixel shading instead I have got per vertex shading. This is my current screen and I have marked on example what I mean talking about shading:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:20:48+00:00Added an answer on May 28, 2026 at 7:20 pm

    This equation:

    gl_FragColor = gl_FrontLightModelProduct.sceneColor + (texture2D(myTexture, vTexCoord)) + finalColor;
    

    Does not make any sense for most textures. You are taking the color produced from the lighting equation and adding it to the color sampled from the texture. This would only make sense if the values stored in the texture represented light emitting properties of the surface.

    Generally, color values of a texture represent the diffuse reflectance of a surface. Which means you need to incorporate them into the lighting equation directly. The texture’s color should either fully replace the diffuse color from the material or it should be combined with the material diffuse color in some way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got a problem with a query I'm trying to write. I have a table
I've got a problem I can't find any solution for. I have a textfile
I am starting using FMOD API and I have got problem with sound playing.
I have got a problem with GridView because I do not understand how can
I have got a problem and a solution, but I am not really satisfied
has any one using Spring MVC with Jquery! i have got a strange problem
have got a problem with do this kind of code , can't figure how
I have got some problem implementing bullet physics into my opengl game. The thing
I have got an strange problem but I am quite sure, for you it
Hello i have got a problem, if I try to display maps with using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.