Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- //Disable string safety warning
- #pragma warning(disable:4996)
- //STD
- #include <stdio.h>
- #include <iostream>
- #include <assert.h>
- //GL
- #include <GLee5_4/GLee.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <gl/glut.h>
- //SDL
- #include <SDL.h>
- #include <SDL_opengl.h>
- static const char* const sourceVert =
- "void main() {\n"
- " gl_Position = gl_Vertex + vec4(0.5);\n"
- "}";
- static void checkShader(const GLuint id, const GLenum type, const char str[]) {
- static char msg[240];
- int size,aux;
- glGetObjectParameterivARB(id, type, &size);
- if(!size) return;
- glGetObjectParameterivARB(id, GL_OBJECT_INFO_LOG_LENGTH_ARB, &size);
- assert(size < sizeof(msg));
- glGetInfoLogARB(id, size, &aux, msg);
- msg[size] = 0;
- printf("%s: \"%s\"\n", str, msg);
- }
- int main(int argc, char **argv) {
- printf("Beginning to test EXT_TRANSFORM_FEEDBACK\n");
- SDL_Init(SDL_INIT_EVERYTHING);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
- SDL_SetVideoMode(400,300,32,SDL_HWSURFACE|SDL_OPENGL);
- GLuint shid, bid, tmp;
- GLint loc;
- printf("Initialization complete (current error: %d)\n\n",glGetError());
- printf("Loading shader\n");
- shid = glCreateProgramObjectARB();
- tmp = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
- glShaderSourceARB(tmp, 1, (const GLcharARB**)&sourceVert, NULL);
- glCompileShaderARB(tmp);
- checkShader(tmp, GL_OBJECT_COMPILE_STATUS_ARB, "Compile vertex");
- glAttachObjectARB(shid,tmp);
- glLinkProgramARB(shid);
- checkShader(shid, GL_OBJECT_LINK_STATUS_ARB, "Link result");
- printf("Shader loaded (current error: %d)\n\n", glGetError());
- printf("Trying to get location of \"gl_Position\"\n");
- glUseProgramObjectARB(shid);
- loc = glGetVaryingLocationNV(shid,"gl_Position");
- printf("Got location %d (current error: %d)\n\n",loc,glGetError());
- //const char *vars[] = {"out_pos"};
- //glTransformFeedbackVaryingsEXT(shid, 1, vars, GL_SEPARATE_ATTRIBS_EXT); //for GLew?
- const GLint locations[] = {loc};
- glTransformFeedbackVaryingsEXT(shid, 1, locations, GL_SEPARATE_ATTRIBS_EXT); //for GLee?
- printf("Preparing buffer\n");
- glGenBuffersARB(1, &bid);
- glBindBufferARB(GL_ARRAY_BUFFER, bid);
- const float init[] = {0.1f,0.2f,0.3f,0.4f};
- glBufferDataARB(GL_ARRAY_BUFFER, 4*sizeof(float)*1, NULL, GL_STREAM_DRAW);
- printf("Buffer prepared (current error: %d)\n",glGetError());
- glBindBufferBaseEXT(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, 0, bid);
- printf("Feedback assigned (current error: %d)\n\n",glGetError());
- printf("Beginning drawing\n");
- glUseProgramObjectARB(shid);
- glBeginTransformFeedbackEXT(GL_POINTS);
- glEnable(GL_RASTERIZER_DISCARD_EXT);
- glBegin(GL_POINTS);
- printf("In data: ");
- for(int i=0; i<4; ++i) {
- printf("%.1f ", init[i]);
- }
- printf("\n");
- glVertex4fv(init);
- glEnd();
- glDisable(GL_RASTERIZER_DISCARD_EXT);
- glEndTransformFeedbackEXT();
- printf("Drawing completed (current error: %d)\n\n", glGetError());
- printf("Reading (hopefully transformed) data\n");
- float *const data = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);
- printf("Out data: ");
- for(int i=0; i<4; ++i) {
- printf("%.1f ", data[i]);
- }
- printf("\n");
- glUnmapBuffer(GL_ARRAY_BUFFER);
- printf("Readback complete (current error: %d)",glGetError());
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement