logo
down
shadow

Multiple spotlights in opengl doesn't work


Multiple spotlights in opengl doesn't work

By : Dániel Horváth
Date : October 24 2020, 06:10 PM
around this issue You are only ever setting LIGHT1, which means only 1 light is going to have been enabled (the last one). If you specify GL_LIGHT0 + index, you'll be able to enable more.
code :
void SpotLight::addlight(int index) {

    glEnable(GL_LIGHT0 + index);

    glLightfv(GL_LIGHT0 + index, GL_DIFFUSE, color);
    glLightfv(GL_LIGHT0 + index, GL_SPECULAR, color);
    glLightfv(GL_LIGHT0 + index, GL_POSITION, position);

    glLightfv(GL_LIGHT0 + index, GL_SPOT_DIRECTION, direction);
    glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, cutoff);
    glLightf(GL_LIGHT0 + index, GL_SPOT_EXPONENT, exponent);
}
void CreateLamps::Add() {

    std::vector<SpotLight>::iterator it = lamp.begin();

    while (it != lamp.end())
    {

        glPushMatrix();
        glTranslatef(1, 0, 30.0);
        glTranslatef(it->position[0], it->position[3] * 3, it->position[2]);
        glRotatef(100.f, -5.0, -10, 0);
        it->addlight(it - lamp.begin());
        it->draw();
        it++;
        glPopMatrix();

    }
}
int numLights = 0;
glGetIntegerv(GL_MAX_LIGHTS, &numLights);
std::cout << "GL_MAX_LIGHTS " << numLights << std::endl;


Share : facebook icon twitter icon
OpenGL Shader doesnt work correctly in an AMD machine

OpenGL Shader doesnt work correctly in an AMD machine


By : lmalunin
Date : March 29 2020, 07:55 AM
I wish this help you I had to do 2 things to solve the problem.
First, to make it work with the AMD card as wells, I had to get and use the AttribLocation.
code :
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
l_vertex = glGetAttribLocation(shaderProgram, "vertex");
glEnableVertexAttribArray(l_vertex);
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glVertexAttribPointer(l_vertex, 3, GL_FLOAT, GL_FALSE, 0, 0);
C++ Opengl Lighting doesnt work

C++ Opengl Lighting doesnt work


By : user3110821
Date : March 29 2020, 07:55 AM
this will help I've already searched for the solution, but none worked. I have already inited the Lighting and all but the objects stay unlit. , You are using glut functions without first calling glutInit.
code :
main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    ...
How can one create smooth edged spotlights in OpenGL?

How can one create smooth edged spotlights in OpenGL?


By : user3432410
Date : March 29 2020, 07:55 AM
Hope that helps There are to ways you can achieve that:
Continue using per-vertex lighting. You, however, should increase the resolution of your scene - put more polygons inside! Change to per-pixel lighting. You will need to learn shader programs. Here are some tutorials on the topic.
OpenGL and Qt 5.5: glm::perspective doesnt work

OpenGL and Qt 5.5: glm::perspective doesnt work


By : acuser
Date : March 29 2020, 07:55 AM
Does that help You MUST pass the QMatrix4x4 transposed matrix of the glm matrix.
Then instead of using.
code :
shaders->setUniformValue(projIndex, QMatrix4x4(glm::value_ptr(proj)) );
shaders->setUniformValue(projIndex, QMatrix4x4(glm::value_ptr(proj)).transposed());
OpenGL Camera Strafing doesnt work

OpenGL Camera Strafing doesnt work


By : 91pdf
Date : March 29 2020, 07:55 AM
this will help Okay, I finally got the solution... As you can see, I am using GLM for my matrix math. GLM stores its matrices values in column major order. Open GL wants column major ordered matrices, too. C/C++ native 2d Array layout is row major, so most of the available OpenGL/C++ tutorials state, that one should use
code :
    glUniformMatrix4fv(location, 1, GL_TRUE, &mat[0][0]);
    glUniformMatrix4fv(location, 1, GL_FALSE, &mat[0][0]);
Related Posts Related Posts :
  • What's wrong with these pointer initialization
  • Access Violation Using memcpy or Assignment to an Array in a Struct
  • Wrong operator() overload called
  • Subtractively sweep a solid through another in python (or C++)
  • boost ublas: rotate 2d vector
  • How can a Windows program temporarily change its time zone?
  • small & readable scheme interpreter in C++?
  • Cannot change the height of a combo box in the VS Dialog Editor
  • Access reading error when using class member variable
  • How to tell if two exe's are the same code-wise?
  • Modifying an old Windows program not to call exit after a keypress without source access
  • What is name lookup mechanism?
  • What does the C++ compiler error "looks like a function definition, but there is no parameter list;" mean?
  • Why does this crash with access violation to 0xcccccc...?
  • How to find out how namespace got polluted?
  • What is the _REENTRANT flag?
  • Managing many objects at once
  • How to create ActiveX DLL in Visual C++
  • Generic allocator class without variadic templates?
  • Comparation in JNI
  • Using a function with reference as a function with pointers?
  • How to initialize an unsigned long long type?
  • How to practically customize IE context menu?
  • Trying to Create a ToolBar with an ImageList, not working
  • How does the destructor know when to activate itself? Can it be relied upon?
  • Conway's Game of Life - C++ and Qt
  • Accessing any structs members at run-time
  • Including #includes in header file vs source file
  • How does switch compile in Visual C++ and how optimized and fast is it?
  • How to override nested C++ objects methods?
  • penalty for "inlined" classes
  • C++ Library for implementing a web services api over legacy code?
  • C++-Singleton class
  • Floating point precision in Visual C++
  • Compiler error when overriding virtual methods
  • What is the point of function pointers?
  • Which is faster in memory, ints or chars? And file-mapping or chunk reading?
  • ISO file in C++
  • Expected Class-name before { token
  • Can I trust floats or doubles representing integers to retain precision?
  • Qt execute multiple get with QNetworkAccessManager
  • Big and Little endian question
  • Visual Studio 2008 compiles anything in C++ file?
  • C++ pointer to functions, Beginner Question
  • Fastest algorithm for primality test
  • Passing array of pointers to another class
  • Handling macro redefinition without modifying .h files ... C / C++ language
  • Implement SSL with SSPI: How to start?
  • Creating a simple VS2008 visualizer inside autoexp.dat (problem with casting)
  • C++ - Unicode Newline
  • Program crashing with 'std::out_of_range' error
  • Use signed or unsigned char in constructing CString?
  • Parallel execution policies in C++ 17
  • C++ Class Templates (Queue of a class)
  • Convert image into useable byte array in C?
  • pointer to preallocated memory as an input parameter and have the function fill it
  • Animated Image in Win32
  • error on compiling statically linked library created in Qt
  • How to easily pass a very long string to a worker process under Windows?
  • Can a class add friend classes at runtime in C++?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk