We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4650 - glEnd() produces GL_INVALID_OPERATION when version is set
Summary: glEnd() produces GL_INVALID_OPERATION when version is set
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.9
Hardware: x86_64 macOS 10.13
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-01 08:25 UTC by Willem
Modified: 2019-06-21 12:33 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Willem 2019-06-01 08:25:45 UTC
I get a GL_INVALID_OPERATION when using `glBegin() .. glEnd()` with SDL_GL_CONTEXT_PROFILE_MASK.  The problem occurs with Version 3.2 and version 4.1 on my machine.


Note: OS is actually Mac OS 10.14 (it is not in the list)

I think it is a Mac OS issue - but maybe there is some kind of workaround?  I would really like to use version 4.1.

Code to reproduce (minimal exmaple).
---

#include <SDL.h>
#include <SDL_opengl.h>

#include <stdio.h>

int main(int argc, char* argv[]) {
  SDL_Init(SDL_INIT_VIDEO);
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

  // comment out the next 3 lines and the error will not occur
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

  static const int width = 800;
  static const int height = 600;

  SDL_Window* window =
      SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                       width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
  SDL_GLContext context = SDL_GL_CreateContext(window);

  glClearColor(0.0, 0.0, 0.0, 0.0);
  glViewport(0, 0, width, height);

  for (;;) {
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_LINES);
    glVertex3f(0.0f, 0.0f, 0.0f);
    glVertex3f(50.0f, 50.0f, 50.0f);
    glEnd();  // check for errors
    auto code = glGetError();
    if (code) {
      if (code == GL_INVALID_OPERATION)
        printf("Error: GL_INVALID_OPERATION\n");
      else
        printf("Other error: %d\n", code);
    }
    SDL_Event event;
    while (SDL_PollEvent(&event)) {
      switch (event.type) {
        case SDL_KEYUP:
          if (event.key.keysym.sym == SDLK_ESCAPE)
            return 0;
          break;
      }
    }
    SDL_GL_SwapWindow(window);
    SDL_Delay(1);
  }

  SDL_GL_DeleteContext(context);
  SDL_DestroyWindow(window);
  SDL_Quit();

  return 0;
}
---
Comment 1 Alex Szpakowski 2019-06-11 14:48:22 UTC
This is actually intended / correct behaviour on macOS' part. Core Profile OpenGL contexts remove a lot of legacy functionality in OpenGL's APIs that was superseded by more modern APIs, glBegin/glEnd is one such example.

In this pdf, everything in blue is gone in Core Profile GL3.2+ contexts and has replacements that match modern hardware more closely: https://www.khronos.org/files/opengl-quick-reference-card.pdf
Comment 2 Willem 2019-06-21 12:33:41 UTC
Thanks for the info