• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

Why not display correctly?

1 post in this topic

It seems mixed together in some vertex, see the attachement!


I modifiedsource code from  http://ogldev.atspace.co.uk/www/tutorial38/tutorial38.html

Because they use glsl4.1,  can't run my computer!




code snippet in mesh.cpp  Mesh::InitFromScene:


      glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[POS_VB]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Positions[0]) * Positions.size(), &Positions[0], GL_STATIC_DRAW);
int VSInput_Position = glGetAttribLocationARB (g_shaderProg, "VSInput_Position");
    glVertexAttribPointer(VSInput_Position, 3, GL_FLOAT, GL_FALSE, 0, 0);    

    glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[TEXCOORD_VB]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(TexCoords[0]) * TexCoords.size(), &TexCoords[0], GL_STATIC_DRAW);
int VSInput_TexCoord = glGetAttribLocationARB (g_shaderProg, "VSInput_TexCoord");
    glVertexAttribPointer(VSInput_TexCoord, 2, GL_FLOAT, GL_FALSE, 0, 0);

       glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[NORMAL_VB]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Normals[0]) * Normals.size(), &Normals[0], GL_STATIC_DRAW);
int VSInput_Normal = glGetAttribLocationARB (g_shaderProg, "VSInput_Normal");
    glVertexAttribPointer(VSInput_Normal, 3, GL_FLOAT, GL_FALSE, 0, 0);

       glBindBuffer(GL_ARRAY_BUFFER, m_Buffers[BONE_VB]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(Bones[0]) * Bones.size(), &Bones[0], GL_STATIC_DRAW);
int VSInput_BoneIDs = glGetAttribLocationARB (g_shaderProg, "VSInput_BoneIDs");
    glVertexAttribPointer(VSInput_BoneIDs, 4, GL_INT, GL_FALSE,  sizeof(VertexBoneData), (const GLvoid*)0);
int VSInput_Weights = glGetAttribLocationARB (g_shaderProg, "VSInput_Weights");
    glVertexAttribPointer(VSInput_Weights, 4, GL_FLOAT, GL_FALSE, sizeof(VertexBoneData), (const GLvoid*)16);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(Indices[0]) * Indices.size(), &Indices[0], GL_STATIC_DRAW);


vertex shader:


#version 110
attribute  vec3  VSInput_Position;                                             
attribute  vec2  VSInput_TexCoord;                                             
attribute  vec3  VSInput_Normal;    
attribute  vec4 VSInput_BoneIDs;
attribute  vec4  VSInput_Weights;
varying    vec2 VSOutput_TexCoord;     
varying    vec3 VSOutput_Normal;
varying    vec3 VSOutput_WorldPos;     
const int MAX_BONES = 100;
uniform mat4 gWVP;
uniform mat4 gWorld;
uniform mat4 gBones[MAX_BONES];
void main()
    mat4 BoneTransform = gBones[int(floor(VSInput_BoneIDs[0]))] * VSInput_Weights[0];
    BoneTransform     += gBones[int(floor(VSInput_BoneIDs[1]))] * VSInput_Weights[1];
    BoneTransform     += gBones[int(floor(VSInput_BoneIDs[2]))] * VSInput_Weights[2];
    BoneTransform     += gBones[int(floor(VSInput_BoneIDs[3]))] * VSInput_Weights[3];
    vec4 PosL      = BoneTransform * vec4(VSInput_Position, 1.0);
    gl_Position    = gWVP * PosL;
    VSOutput_TexCoord = VSInput_TexCoord;
    vec4 NormalL   = BoneTransform * vec4(VSInput_Normal, 0.0);
    VSOutput_Normal   = (gWorld * NormalL).xyz;
    VSOutput_WorldPos = (gWorld * PosL).xyz;                                

fragment shader:


#version 120
struct VSOutput
    vec2 TexCoord;                                                                 
    vec3 Normal;                                                                   
    vec3 WorldPos;                                                                 

struct VSOutput1
    vec2 TexCoord;                                                                 
    vec3 Normal;                                                                   
    vec3 WorldPos;                                                                 

const int MAX_POINT_LIGHTS = 2;
const int MAX_SPOT_LIGHTS = 2;

struct BaseLight
    vec3 Color;
    float AmbientIntensity;
    float DiffuseIntensity;

struct DirectionalLight
    BaseLight Base;
    vec3 Direction;
struct Attenuation                                                                  
    float Constant;                                                                 
    float Linear;                                                                   
    float Exp;                                                                      
struct PointLight                                                                           
    BaseLight Base;                                                                  
    vec3 Position;                                                                          
    Attenuation Atten;                                                                      
struct SpotLight                                                                            
    PointLight Base;                                                                 
    vec3 Direction;                                                                         
    float Cutoff;                                                                           
uniform int gNumPointLights;                                                                
uniform int gNumSpotLights;                                                                 
uniform DirectionalLight gDirectionalLight;                                                 
uniform PointLight gPointLights[MAX_POINT_LIGHTS];                                          
uniform SpotLight gSpotLights[MAX_SPOT_LIGHTS];                                             
uniform sampler2D gColorMap;                                                                
uniform vec3 gEyeWorldPos;                                                                  
uniform float gMatSpecularIntensity;                                                        
uniform float gSpecularPower;

vec4 CalcLightInternal(BaseLight Light, vec3 LightDirection, VSOutput1 In)            
    vec4 AmbientColor = vec4(Light.Color, 1.0f) * Light.AmbientIntensity;                   
    float DiffuseFactor = dot(In.Normal, -LightDirection);                                     
    vec4 DiffuseColor  = vec4(0, 0, 0, 0);                                                  
    vec4 SpecularColor = vec4(0, 0, 0, 0);                                                  
    if (DiffuseFactor > 0) {                                                                
        DiffuseColor = vec4(Light.Color, 1.0f) * Light.DiffuseIntensity * DiffuseFactor;    
        vec3 VertexToEye = normalize(gEyeWorldPos - In.WorldPos);                             
        vec3 LightReflect = normalize(reflect(LightDirection, In.Normal));                     
        float SpecularFactor = dot(VertexToEye, LightReflect);                              
        SpecularFactor = pow(SpecularFactor, gSpecularPower);                               
        if (SpecularFactor > 0) {                                                           
            SpecularColor = vec4(Light.Color, 1.0f) *                                       
                            gMatSpecularIntensity * SpecularFactor;                         
    return (AmbientColor + DiffuseColor + SpecularColor);                                   
vec4 CalcDirectionalLight(VSOutput1 In)                                                      
    return CalcLightInternal(gDirectionalLight.Base, gDirectionalLight.Direction, In);  
vec4 CalcPointLight(PointLight l, VSOutput1 In)                                       
    vec3 LightDirection = In.WorldPos - l.Position;                                           
    float Distance = length(LightDirection);                                                
    LightDirection = normalize(LightDirection);                                             
    vec4 Color = CalcLightInternal(l.Base, LightDirection, In);                         
    float Attenuation =  l.Atten.Constant +                                                 
                         l.Atten.Linear * Distance +                                        
                         l.Atten.Exp * Distance * Distance;                                 
    return Color / Attenuation;                                                             
vec4 CalcSpotLight(SpotLight l, VSOutput1 In)                                         
    vec3 LightToPixel = normalize(In.WorldPos - l.Base.Position);                             
    float SpotFactor = dot(LightToPixel, l.Direction);                                      
    if (SpotFactor > l.Cutoff) {                                                            
        vec4 Color = CalcPointLight(l.Base, In);                                        
        return Color * (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - l.Cutoff));                   
    else {                                                                                  
        return vec4(0,0,0,0);                                                               
void main(in VSOutput FSin, out vec4 FragColor)
    VSOutput1 In;
    In.TexCoord = FSin.TexCoord;
    In.Normal = normalize(FSin.Normal);
    In.WorldPos = FSin.WorldPos;                                                                 
    vec4 TotalLight = CalcDirectionalLight(In);                                         
    for (int i = 0 ; i < gNumPointLights ; i++) {                                           
        TotalLight += CalcPointLight(gPointLights[i], In);                              
    for (int i = 0 ; i < gNumSpotLights ; i++) {                                            
        TotalLight += CalcSpotLight(gSpotLights[i], In);                                
    FragColor = texture(gColorMap, In.TexCoord.xy) * TotalLight;     


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0