Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: How are GLfloat supposed to be initialized? Using floats/doubles or explicit casting?

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2018
    Posts
    10

    How are GLfloat supposed to be initialized? Using floats/doubles or explicit casting?

    How are GLfloat supposed to be initialized? Using floats/doubles or explicit casting?

    Particularly, I have the following code:

    Code :
    GLfloat diffColors[4][4] = { { 0.5, 0.5, 0.9, 1.0 },
    	{ 0.9, 0.5, 0.5, 1.0 },
    	{ 0.5, 0.9, 0.3, 1.0 },
    	{ 0.3, 0.8, 0.9, 1.0 } };

    which I think used to work, but now the compiler gives
    Code :
    error C2397: conversion from 'double' to 'GLfloat' requires a narrowing conversion

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,058
    Welcome to C++11. This is a breaking change in the standard; the use of braces to initialize things used to be able to lose information due to implicit conversions. Now, they're not.

    Of course, you don't really care in this case, so it's kind of pointless. But the solution is to suffix all of your floating-point literals with `f`. That will make them actual `float`s.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •