Hello , i have tried everything but this error wont go away.
Have tried renaming the struct and the array Points but nothing works.
Tried rebuilding the class but it wont have an array at all! Please help me :)
The link error from visual studio 2005 is :
1>------ Build started: Project: sdl, Configuration: Release Win32 ------
1>Compiling...
1>Project.cpp
1>Linking...
1>surface.obj : warning LNK4006: "struct SurfacePoint (* Points)[4]" (?Points@@3PAY0 3USurfacePoint@ @A) already defined in Project.obj; second definition ignored
1>E:\c++\sdl2\R elease\sdl.exe : warning LNK4088: image being generated due to /FORCE option; image may not run
1>Generating code
1>Finished generating code
1> CIL library( CIL module) : warning LNK4006: "struct SurfacePoint (* Points)[4]" (?Points@@3PAY0 3USurfacePoint@ @A) already defined in CIL library( CIL module); second definition ignored
1>E:\c++\sdl2\R elease\sdl.exe : warning LNK4088: image being generated due to /FORCE option; image may not run
1>Embedding manifest...
1>Build log was saved at "file://e:\c++\sdl2\sdl \Release\BuildL og.htm"
1>sdl - 0 error(s), 4 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Here is surf class:
here is the main file :
Have tried renaming the struct and the array Points but nothing works.
Tried rebuilding the class but it wont have an array at all! Please help me :)
The link error from visual studio 2005 is :
1>------ Build started: Project: sdl, Configuration: Release Win32 ------
1>Compiling...
1>Project.cpp
1>Linking...
1>surface.obj : warning LNK4006: "struct SurfacePoint (* Points)[4]" (?Points@@3PAY0 3USurfacePoint@ @A) already defined in Project.obj; second definition ignored
1>E:\c++\sdl2\R elease\sdl.exe : warning LNK4088: image being generated due to /FORCE option; image may not run
1>Generating code
1>Finished generating code
1> CIL library( CIL module) : warning LNK4006: "struct SurfacePoint (* Points)[4]" (?Points@@3PAY0 3USurfacePoint@ @A) already defined in CIL library( CIL module); second definition ignored
1>E:\c++\sdl2\R elease\sdl.exe : warning LNK4088: image being generated due to /FORCE option; image may not run
1>Embedding manifest...
1>Build log was saved at "file://e:\c++\sdl2\sdl \Release\BuildL og.htm"
1>sdl - 0 error(s), 4 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Here is surf class:
Code:
#include "SDL.h" // SDL: window & input library #include "SDL_opengl.h" // platform independent OpenGL include #include <vector> #include <iostream> #include <fstream> #include <string> #include <math.h> #include <stdio.h> #include <stdlib.h> using namespace std; struct SurfacePoint { float x; float y; float z; }; /// 4x4 grid of SurfacePoints that will define the surface SurfacePoint Points[4][4] = { { { 10,0,10 }, { 5,0,10 }, { -5,0,10 }, {-10,0,10 } }, { { 10,0,5 }, { 5,6,5 }, { -5,6,5 }, {-10,0,5 } }, { { 10,0,-5 }, { 5,6,-5 }, { -5,6,-5 }, {-10,0,-5 } }, { { 10,0,-10 }, { 5,0,-10 }, { -5,0,-10 }, {-10,0,-10 } } }; class surf{ float detail; public: surf(){ detail=(float)0.01; //step for u and v values } void draw(){ glBegin(GL_POINTS); //get SurfacePoints on u curves for (float u=0;u<1;u+=detail){ for(float v=0;v<1;v+=detail){ SurfacePoint p=calculate(u,v); glVertex3f(p.x,p.y,p.z); } } glEnd(); } SurfacePoint calculate(float u, float v){ //calculate 4 SurfacePoints on each u curve SurfacePoint temp[4]; temp[0] = calculate_u(u,0); temp[1] = calculate_u(u,1); temp[2] = calculate_u(u,2); temp[3] = calculate_u(u,3); return calculate_v(v,temp); } SurfacePoint calculate_u(float u, int row){ SurfacePoint p; //BLENDING FUNCTION float b0 = (-3*u*u*u+3*u*u-3*u+1)/6.0f; float b1 = (3*u*u*u - 6*u*u +4)/6.0f; float b2 = (-3*u*u*u +3*u*u + 3*u + 1)/6.0f; float b3 = u*u*u/6.0f; p.x = b0*Points[row][0].x + b1*Points[row][1].x + b2*Points[row][2].x + b3*Points[row][3].x ; p.y = b0*Points[row][0].y + b1*Points[row][1].y + b2*Points[row][2].y + b3*Points[row][3].y ; p.z = b0*Points[row][0].z + b1*Points[row][1].z + b2*Points[row][2].z + b3*Points[row][3].z ; return p; } SurfacePoint calculate_v(float u,SurfacePoint* pts){ SurfacePoint p; float b0 = (-3*u*u*u+3*u*u-3*u+1)/6.0f; float b1 = (3*u*u*u - 6*u*u +4)/6.0f; float b2 = (-3*u*u*u +3*u*u + 3*u + 1)/6.0f; float b3 = u*u*u/6.0f; p.x = b0*pts[0].x + b1*pts[1].x + b2*pts[2].x + b3*pts[3].x ; p.y = b0*pts[0].y + b1*pts[1].y + b2*pts[2].y + b3*pts[3].y ; p.z = b0*pts[0].z + b1*pts[1].z + b2*pts[2].z + b3*pts[3].z ; return p; } };
Code:
/* SDL OpenGL skeleton code. * * by Fredrik Orderud, 2005 */ #include "SDL.h" // SDL: window & input library #include "SDL_opengl.h" // platform independent OpenGL include #include <stdio.h> #include <stdlib.h> #include "surface.cpp" bool running = true; surf t; /* Keyboard callback */ static void handle_key_down (SDL_keysym* keysym) { switch( keysym->sym ) { case SDLK_ESCAPE: case SDLK_q: case SDLK_x: running = false; break; case SDLK_SPACE: // do something :) break; } } /* General event callback */ static void process_events () { SDL_Event event; // Grab all the events off the queue while (SDL_PollEvent(&event)) { switch( event.type ) { case SDL_KEYDOWN: // key presses handle_key_down( &event.key.keysym ); break; case SDL_QUIT: // quit requests (like Ctrl-c) running = false; break; } } } /* Render scene */ static void draw_scene () { // clear image- and depth buffer to get a clean canvas glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // set up geometric transformations glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f,-6.0f,-10.0f); // Now looking in negative Z-direction from origo // +X is right and +Y is up t.draw(); /* TODO: Insert geometric camera-transformation code here to convert from "camera" to "world" frame */ //Render object(s) // TODO: REPLACE CODE HERE // Swap on-screen/off-screen buffers (double buffering) SDL_GL_SwapBuffers( ); } /* Initialize OpenGL */ static void setup_opengl( int width, int height ) { // Gouraud shading model (smooth) glShadeModel(GL_SMOOTH); // enable backface culling glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); // Set black clear color glClearColor(0, 0, 0, 0); // Enable Z-buffer (corrects drawing order) glEnable(GL_DEPTH_TEST); // Let viewport cover entire window glViewport(0, 0, width, height); // Change to the projection matrix and set our viewing volume. glMatrixMode(GL_PROJECTION); glLoadIdentity(); float ratio = (float) width / (float) height; gluPerspective(60.0, ratio, 1.0, 1024.0); } /* Program entry point */ int main (int argc, char* argv[]) { // window dimensions int width = 640; int height = 480; // initialize SDL's video subsystem if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) ); return -1; } // retrieve video information const SDL_VideoInfo *info = SDL_GetVideoInfo( ); if (!info) { fprintf( stderr, "Video query failed: %s\n", SDL_GetError( ) ); return -1; } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8 ); // min 8bit red SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8 ); // min 8bit green SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8 ); // min 8bit blue SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); // 16bit depth buffer SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); // require double buffering // Set video mode SDL_Surface * surface = SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, SDL_OPENGL); if (!surface) { fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) ); return -1; } // OpenGL initialization setup_opengl(width, height); // main event loop while (running) { // Process incoming events process_events(); // Draw the screen draw_scene(); SDL_Delay(10/5); // 5fps } SDL_Quit(); // unload SDL return 0; }
Comment