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: Need help fixing "unresolved external symbol glDrawArrays" issue.

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    17

    Need help fixing "unresolved external symbol glDrawArrays" issue.

    I'm following the tutorial at open.gl (just type this into the address bar, it seems new accounts here can't post urls) and everything has worked fine up until trying to call glDrawArrays.

    Could someone explain what I'm missing?

    I'm using SFML for the window context, so here are my headers:

    Code :
    #include <iostream>
    #include <fstream>
    #include <SFML/System.hpp>
    #include <SFML/Window.hpp>
    #include <GL/glew.h>
    #include <GL/wglew.h>

    And I'm linking to the following libraries:

    Code :
    sfml/sfml-system.lib
    sfml/sfml-window.lib
    gl/glew32.lib

    I'm doing this on a Windows 8 machine using MSVS Express 2012; my graphics card is OpenGL 4.2 capable. Am I missing a header declaration or a library?

    EDIT: I'll just post the full code here as well since it's not much.

    Code :
    #include <iostream>
    #include <fstream>
    #include <SFML/System.hpp>
    #include <SFML/Window.hpp>
    #include <GL/glew.h>
    #include <GL/wglew.h>
    using namespace std;
     
    string GetFile(const char * filename);
     
    int main()
    {
    	sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Close);
    	glewExperimental = GL_TRUE;
    	glewInit();
     
    	GLuint vbo;
    	glGenBuffers(1, &vbo);
    	glBindBuffer(GL_ARRAY_BUFFER, vbo);
     
    	float vertices[] =
    	{
    		0.0f, 0.5f,
    		0.5f, -0.5f,
    		-0.5f, -0.5f
    	};
     
    	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
     
     
    	const GLchar * vertexSource = GetFile("vertex.vert").c_str();
    	GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
    	glShaderSource(vertexShader, 1, &vertexSource, NULL);
    	glCompileShader(vertexShader);
     
    	GLint status;
    	glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &status);
     
    	cout << (status == GL_TRUE) << endl;
     
    	const GLchar * fragmentSource = GetFile("fragment.frag").c_str();
    	GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
    	glShaderSource(fragmentShader, 1, &fragmentSource, NULL);
    	glCompileShader(fragmentShader);
     
    	GLuint shaderProgram = glCreateProgram();
    	glAttachShader(shaderProgram, vertexShader);
    	glAttachShader(shaderProgram, fragmentShader);
    	glLinkProgram(shaderProgram);
    	glUseProgram(shaderProgram);
     
    	GLuint vao;
    	glGenVertexArrays(1, &vao);
    	glBindVertexArray(vao);
     
    	GLint posAttribute = glGetAttribLocation(shaderProgram, "position");
    	glVertexAttribPointer(posAttribute, 2, GL_FLOAT, GL_FALSE, 0, 0);
    	glEnableVertexAttribArray(posAttribute);
     
    	while(window.isOpen())
    	{
    		sf::Event windowEvent;
    		while(window.pollEvent(windowEvent))
    		{
    			switch(windowEvent.type)
    			{
    			case sf::Event::Closed:
    				window.close();
    				break;
    			}
    		}
    		glDrawArrays(GL_TRIANGLES, 0, 3);
    	}
    	return 0;
    }
     
    string GetFile(const char * filename)
    {
    	ifstream in(filename, std::ios::in | std::ios::binary);
    	if(in)
    	{
    		string contents;
    		in.seekg(0, std::ios::end);
    		contents.resize(in.tellg());
    		in.seekg(0, std::ios::beg);
    		in.read(&contents[0], contents.size());
    		in.close();
    		return(contents);
    	}
     
    	return "";
    }

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2013
    Posts
    17
    Fixed it. It seems Glew isn't enough, I needed to link to opengl32.lib (and include the dll, of course).

Posting Permissions

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